Message30326
I ran into problems pickling a set containing an int
subclass which holds a reference to an object which
holds a reference to the original object.
I reduced it to the attached
int_subclass_pickle_problem.py. There are no problems
with pickle protocols 0 and 1, but the protocol 2 unit
tests fail with an exception.
This happens for pickle and cPickle both, although with
two different excpeptions.
cPickle:
TypeError: ('set objects are unhashable', <type 'set'>,
([set([1])],))
pickle:
File "....\lib\pickle.py", line 244, in memoize
assert id(obj) not in self.memo
AssertionError
(For the full tracebacks, run the attached script.)
I looked into if this was because int implemented
__reduce__ or __reduce_ex__, trumping my
__getstate__/__setstate__, but that doesn't seem to be
the case:
>>> int.__reduce_ex__ is object.__reduce_ex__
True
>>> int.__reduce__ is object.__reduce__
True
After the further simplification of replacing
self.orig = [set([E.a]), set([E.a])]
with
self.orig = E.a
cPickle starts working, but pickle still fails.
(Seen with Python 2.4.3 and Python 2.5, on W2K.) |
|
Date |
User |
Action |
Args |
2007-08-23 14:44:12 | admin | link | issue1581183 messages |
2007-08-23 14:44:12 | admin | create | |
|