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 <rep...@bugs.python.org>
<http://bugs.python.org/issue30691>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to