[New-bugs-announce] [issue2295] cPickle corner case - docs or bug?

Greg Kochanski report at bugs.python.org
Sat Mar 15 20:18:46 CET 2008


New submission from Greg Kochanski <gpk at users.sourceforge.net>:

If you attempt to cPickle a class, cPickle checks
that it can get the identical class by importing it.

If that check fails, it reports:
Traceback (most recent call last):
...
"/usr/local/lib/python2.5/site-packages/newstem2-0.12.3-py2.5-linux-i686.egg/newstem2/stepperclient.py",
line 41, in send
    s = cPickle.dumps( args, cPickle.HIGHEST_PROTOCOL)
cPickle.PicklingError: Can't pickle <class 'test_simple2.aModel'>: it's
not the same object as test_simple2.aModel
$ 

Normally, this is probably a good thing.   However, if you do
an import using the "imp" module, via
 imp.load_module(name, fd, pn, desc), you get the "same" module
containing the "same" classes, but everything is duplicated at
different addresses.  In other words, you get distinct class
objects from what cPickle
will find.   Consequently, the when cPickle makes the
"is" comparison between what you gave it and what it can find,
it will fail and cause an error.

In this case, the error is wrong. I know that the aModel classes
come from the same file and are member-for-member the same.

This may well be a documentation
error:  it needs to mention this test and note that classes in modules
imported
via imp are not picklable.    Or, imp needs to note that its results
are not picklable.   Or both.

Or, maybe it's something that should be fixed, though I'm not
sure if there is a general solution that will always behave
well.

----------
assignee: georg.brandl
components: Documentation, Library (Lib)
messages: 63560
nosy: georg.brandl, gpk
severity: normal
status: open
title: cPickle corner case - docs or bug?
type: behavior
versions: Python 2.5

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2295>
__________________________________


More information about the New-bugs-announce mailing list