[Python-Dev] Strange memo behavior from cPickle

Bruce Christensen t-bruch at microsoft.com
Tue Aug 1 23:52:42 CEST 2006

We seem to have stumbled upon some strange behavior in cPickle's memo
use when pickling instances.

Here's the repro:

class C:
    def __getstate__(self): return ('s1', 's2', 's3')

[interactive interpreter]
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
>>> import cPickle
>>> import mymodule
>>> class C:
...     def __getstate__(self): return ('s1', 's2', 's3')
>>> for x in mymodule.C(), C(): cPickle.dumps(x)

Note that the second and third strings in the instance's state are
memoized in the first case, but not in the second. Any idea why this
occurs (and why the first element is never memoized)?


More information about the Python-Dev mailing list