[issue30691] WeakSet is not pickleable

Serhiy Storchaka report at bugs.python.org
Sun Jun 18 01:58:43 EDT 2017


Serhiy Storchaka added the comment:

The method is broken (and always was). Pickling doesn't work because the state contains unpickleable object. Copying works incorrectly, since the pickle state contains references to the original WeakSet and it overrides the __dict__ of the copy, making its state inconsistent. If the purpose of implementing the __reduce__ method was the support of the copying, the __reduce__ method should be fixed or the copying should be implemented with implementing the __copy__ and __deepcopy__ methods.

However there is a subtle moment with pickling WeakSet (as well as with pickling weakref.proxy, see issue18068). The problem is that if you pickled a WeakSet, but not hard references to its items, the items will be disappeared just after unpickling, since they have no hard references. This may confuse. If you pickle also hard refereces to the items, a WeakSet can be pickled and unpickled as expected (after fixing __reduce__).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30691>
_______________________________________


More information about the Python-bugs-list mailing list