[ python-Bugs-750328 ] Pickle fails to restore new-style class instance in a cycle
SourceForge.net
noreply at sourceforge.net
Thu Sep 1 00:04:23 CEST 2005
Bugs item #750328, was opened at 2003-06-06 23:13
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=750328&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Type/class unification
Group: Python 2.2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Phillip J. Eby (pje)
Assigned to: Nobody/Anonymous (nobody)
Summary: Pickle fails to restore new-style class instance in a cycle
Initial Comment:
Here is code to demonstrate the problem. All asserts
succeed except the last, showing that pickle and
cPickle both handle a "classic" cycle correctly, but
only cPickle handles new-style cycles correctly. It
would appear that the problem is that the pure-Python
pickle isn't putting the object into its 'memo' until
*after* the object's state has been pickled. Thus, the
identity is not preserved on unpickling. This may be
true for other object types that use __reduce__, but I
have not verified this.
import pickle, cPickle
class X: pass
x = X()
x.x = x
x2 = cPickle.loads(cPickle.dumps(x))
assert x2.x is x2
x2 = pickle.loads(pickle.dumps(x))
assert x2.x is x2
class Y(object): pass
y = Y()
y.y = y
y2 = cPickle.loads(cPickle.dumps(y))
assert y2.y is y2
# this fails
y2 = pickle.loads(pickle.dumps(y))
assert y2.y is y2
----------------------------------------------------------------------
>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-09-01 00:04
Message:
Logged In: YES
user_id=1188172
Runs find in 2.5cvs too.
----------------------------------------------------------------------
Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-05-31 13:34
Message:
Logged In: YES
user_id=1188172
Runs fine in Py2.4.1 too, so should it be considered fixed?
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-07-01 05:00
Message:
Logged In: YES
user_id=80475
Another datapoint: This above script runs fine in Py2.3b2.
----------------------------------------------------------------------
Comment By: Steven Taschuk (staschuk)
Date: 2003-06-08 22:23
Message:
Logged In: YES
user_id=666873
Compare bug 702858, which observes the same behaviour for
copy.deepcopy.
The common parts of pickle and copy really ought to be merged.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=750328&group_id=5470
More information about the Python-bugs-list
mailing list