Alexander Belopolsky <belopol...@users.sourceforge.net> added the comment:

Upon further investigation, I conclude that the problem is in the user code.  I 
am attaching int_subclass_pickle_problem_fixed.py which fixes the user code as 
follows:

     def __getnewargs__(self):
-        return (int(self), self.an_enum)
+        return (int(self), None)

Note that with this change, the object is pickled correctly because 
__setstate__ takes care of resetting self.an_enum.

The problem is that self-referential state should not be passed via 
__getnewargs__ mechanism.  This is because when pickler starts writing newargs, 
it is already committed to creating a new object (otherwise it would not need 
to serialize newargs in the first place.)  If the newargs contain the object 
that is being pickled, it will be serialized twice unless this situation is 
caught in memoize.

What can be improved, is the diagnostic and possibly documentation.  If after 
saving newargs, memo contains the object that is being pickled, an exception 
should be raised explaining that __getnewargs__() should not contain 
self-references.

----------
keywords:  -patch
priority: normal -> low

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1581183>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to