Skip to content
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
1.2.3
=====

- Fix a regression in cloudpickle and python3.8 causing an error when trying to
pickle property objects.
([PR #329](https://github.com/cloudpipe/cloudpickle/pull/329)).

- Fix a bug when a thread imports a module while cloudpickle iterates
over the module list
([PR #322](https://github.com/cloudpipe/cloudpickle/pull/322)).
Expand Down
5 changes: 5 additions & 0 deletions cloudpickle/cloudpickle_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ def _root_logger_reduce(obj):
return logging.getLogger, ()


def _property_reduce(obj):
return property, (obj.fget, obj.fset, obj.fdel, obj.__doc__)


def _weakset_reduce(obj):
return weakref.WeakSet, (list(obj),)

Expand Down Expand Up @@ -406,6 +410,7 @@ class CloudPickler(Pickler):
dispatch[logging.Logger] = _logger_reduce
dispatch[logging.RootLogger] = _root_logger_reduce
dispatch[memoryview] = _memoryview_reduce
dispatch[property] = _property_reduce
dispatch[staticmethod] = _classmethod_reduce
dispatch[types.CellType] = _cell_reduce
dispatch[types.CodeType] = _code_reduce
Expand Down
14 changes: 14 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,20 @@ def func(x):
cloned = pickle_depickle(func, protocol=self.protocol)
self.assertEqual(cloned.__qualname__, func.__qualname__)

def test_property(self):
class MyObject:
_value = 1

@property
def value(self):
return self._value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the read-only property, this class should have a read-write property and one should check that the reconstructed instance allows to set the value of the read-write property while it should not be possible for the read-only property of the reconstructed instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the pickling of the __doc__ info is not tested either.

my_object = MyObject()
assert my_object.value == 1

depickled_obj = pickle_depickle(my_object)
assert depickled_obj.value == 1

def test_namedtuple(self):
MyTuple = collections.namedtuple('MyTuple', ['a', 'b', 'c'])
t1 = MyTuple(1, 2, 3)
Expand Down