[ python-Bugs-1443328 ] Pickle protocol 2 fails on private slots.
SourceForge.net
noreply at sourceforge.net
Mon Mar 27 07:50:42 CEST 2006
Bugs item #1443328, was opened at 2006-03-05 05:18
Message generated for change (Comment added) made by zseil
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1443328&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: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Daniele Varrazzo (dvarrazzo)
Assigned to: Tim Peters (tim_one)
Summary: Pickle protocol 2 fails on private slots.
Initial Comment:
The pickling protocol 2 can manage new style objects
defining __slots__ and without __dict__. Anyway it
fails when one of the slots is "private".
>>> class C1(object):
__slots__ = ["__priv"]
def __init__(self):
self.__priv = 42
def get_priv(self):
return self.__priv
>>> C1().get_priv()
42
>>> import pickle
>>> pickle.loads(pickle.dumps(C1(), 2)).get_priv()
Traceback (most recent call last):
File "<pyshell#258>", line 1, in -toplevel-
pickle.loads(pickle.dumps(C1(), 2)).get_priv()
File "<pyshell#255>", line 6, in get_priv
return self.__priv
AttributeError: _C1__priv
of course redefining __getstate__ and __setstate__
bypasses the problem.
the cPickle module shows the same issue.
----------------------------------------------------------------------
Comment By: iga Seilnacht (zseil)
Date: 2006-03-27 07:50
Message:
Logged In: YES
user_id=1326842
The bug is in the copy_reg module.
object.__reduce_ex__ calls function
_slotnames in that module.
There is another bug when __slots__
is a single string. Examples below.
>>> import copy_reg
>>> class A(object):
... __slots__ = ('__spam',)
...
>>> class B(object):
... __slots__ = 'spam'
...
>>> copy_reg._slotnames(A) # should be ['_A__spam']
['__spam']
>>> copy_reg._slotnames(B) # should be ['spam']
['s', 'p', 'a', 'm']
----------------------------------------------------------------------
Comment By: Georg Brandl (gbrandl)
Date: 2006-03-09 09:21
Message:
Logged In: YES
user_id=849994
Confirmed with pickle and cPickle here.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1443328&group_id=5470
More information about the Python-bugs-list
mailing list