Message27680
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. |
|
Date |
User |
Action |
Args |
2007-08-23 14:38:14 | admin | link | issue1443328 messages |
2007-08-23 14:38:14 | admin | create | |
|