Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX pickle getset_descriptor #290

Merged
merged 4 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- Fix a bug affecting bound classmethod saving on Python 2.
([issue #288](https://github.com/cloudpipe/cloudpickle/issues/288))

- Add support for pickling exotic builtin property types.
pierreglaser marked this conversation as resolved.
Show resolved Hide resolved
([issue #290](https://github.com/cloudpipe/cloudpickle/pull/290))

1.2.1
=====

Expand Down
5 changes: 5 additions & 0 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,11 @@ def save_builtin_function_or_method(self, obj):
method_descriptor = type(str.upper)
dispatch[method_descriptor] = save_builtin_function_or_method

def save_getset_descriptor(self, obj):
return self.save_reduce(getattr, (obj.__objclass__, obj.__name__))

dispatch[types.GetSetDescriptorType] = save_getset_descriptor

def save_global(self, obj, name=None, pack=struct.pack):
"""
Save a "global".
Expand Down
5 changes: 5 additions & 0 deletions cloudpickle/cloudpickle_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def _file_reduce(obj):
return _file_reconstructor, (retval,)


def _getset_descriptor_reduce(obj):
return getattr, (obj.__objclass__, obj.__name__)


def _mappingproxy_reduce(obj):
return types.MappingProxyType, (dict(obj),)

Expand Down Expand Up @@ -405,6 +409,7 @@ class CloudPickler(Pickler):
dispatch[staticmethod] = _classmethod_reduce
dispatch[types.CellType] = _cell_reduce
dispatch[types.CodeType] = _code_reduce
dispatch[types.GetSetDescriptorType] = _getset_descriptor_reduce
dispatch[types.ModuleType] = _module_reduce
dispatch[types.MethodType] = _method_reduce
dispatch[types.MappingProxyType] = _mappingproxy_reduce
Expand Down
5 changes: 5 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,11 @@ def test_logger(self):
# logging.Logger object
self.check_logger('cloudpickle.dummy_test_logger')

def test_getset_descriptor(self):
assert isinstance(float.real, types.GetSetDescriptorType)
depickled_descriptor = pickle_depickle(float.real)
self.assertIs(depickled_descriptor, float.real)

def test_abc(self):

@abc.abstractmethod
Expand Down