Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ def save_function(self, obj, name=None):
Determines what kind of function obj is (e.g. lambda, defined at
interactive prompt, etc) and handles the pickling appropriately.
"""
if obj in _BUILTIN_TYPE_CONSTRUCTORS:
try:
should_special_case = obj in _BUILTIN_TYPE_CONSTRUCTORS
except TypeError:
# Methods of builtin types aren't hashable in python 2.
should_special_case = False

if should_special_case:
# We keep a special-cased cache of built-in type constructors at
# global scope, because these functions are structured very
# differently in different python versions and implementations (for
Expand Down
6 changes: 6 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,12 @@ def test_pickle_reraise(self):
with pytest.raises((exc_type, pickle.PicklingError)):
cloudpickle.dumps(obj)

def test_unhashable_function(self):
d = {'a': 1}
depickled_method = pickle_depickle(d.get)
self.assertEquals(depickled_method('a'), 1)
self.assertEquals(depickled_method('b'), None)


class Protocol2CloudPickleTest(CloudPickleTest):

Expand Down