[Python-bugs-list] [ python-Bugs-628925 ] pickle won't dump instances after reload

SourceForge.net noreply@sourceforge.net
Wed, 21 May 2003 18:28:03 -0700


Bugs item #628925, was opened at 2002-10-25 19:18
Message generated for change (Comment added) made by bcannon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=628925&group_id=5470

Category: Python Library
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Dave Cole (davecole)
Assigned to: Nobody/Anonymous (nobody)
Summary: pickle won't dump instances after reload

Initial Comment:
The fix for bug http://python.org/sf/451547 has made
the follow sequence fail:

>>> import pickle, copy
>>> o = copy._EmptyClass()
>>> reload(copy)
<module 'copy' from '/usr/lib/python2.2/copy.pyc'>
>>> pickle.dumps(o, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/pickle.py", line 978, in dumps
    Pickler(file, bin).dump(object)
  File "/usr/lib/python2.2/pickle.py", line 115, in dump
    self.save(object)
  File "/usr/lib/python2.2/pickle.py", line 225, in save
    f(self, object)
  File "/usr/lib/python2.2/pickle.py", line 477, in
save_inst
    save(cls)
  File "/usr/lib/python2.2/pickle.py", line 225, in save
    f(self, object)
  File "/usr/lib/python2.2/pickle.py", line 524, in
save_global
    raise PicklingError(
pickle.PicklingError: Can't pickle <class
copy._EmptyClass at 0x819478c>: it's not the same
object as copy._EmptyClass

Looking at bug 451547 the reported problem was that
pickle would allow you to dump lambdas.  When you try
to dump lambdas you now see the following:

>>> f = lambda x: x in (1,2,3)
>>> s = pickle.dumps(f, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/pickle.py", line 978, in dumps
    Pickler(file, bin).dump(object)
  File "/usr/lib/python2.2/pickle.py", line 115, in dump
    self.save(object)
  File "/usr/lib/python2.2/pickle.py", line 225, in save
    f(self, object)
  File "/usr/lib/python2.2/pickle.py", line 519, in
save_global
    raise PicklingError(
pickle.PicklingError: Can't pickle <function <lambda>
at 0x8157edc>: it's not found as __main__.<lambda>

The reported lambda problem is found without having to
check that the manually resolved class object is at the
same memory address as the class object referenced by
the lambda.  I think the pickle code is being too careful.

>From pickle.py: the "klass is not object" test in the
else clause should probably be removed.

        try:
            __import__(module)
            mod = sys.modules[module]
            klass = getattr(mod, name)
        except (ImportError, KeyError, AttributeError):
            raise PicklingError(
                "Can't pickle %r: it's not found as
%s.%s" %
                (object, module, name))
        else:
            if klass is not object:
                raise PicklingError(
                    "Can't pickle %r: it's not the same
object as %s.%s" %
                    (object, module, name))


----------------------------------------------------------------------

>Comment By: Brett Cannon (bcannon)
Date: 2003-05-21 18:28

Message:
Logged In: YES 
user_id=357491

It's still there for 2.3b1.  It seems to pickle without raising an error when it 
uses the text format.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=628925&group_id=5470