[issue14577] pickling uses __class__ so you can't pickle proxy/mock objects that pretend to be other objects
Michael Foord
report at bugs.python.org
Sat Apr 14 13:28:27 CEST 2012
Michael Foord <michael at voidspace.org.uk> added the comment:
So, changing copyreg.py to use type(self) instead of self.__class__ isn't sufficient. _pickle accesses __class__ as well it seems. However I'm running all tests with this change in place to see if it breaks intended behaviour:
Python 3.3.0a1+ (default:51016ff7f8c9, Mar 26 2012, 13:15:33)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle as p
[70240 refs]
>>> class Foo(object):
... __class__ = property(lambda s: int)
...
[70290 refs]
>>> Foo().__class__
<class 'int'>
[70294 refs]
>>> p.dumps(Foo())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.PicklingError: args[0] from __newobj__ args has the wrong class
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14577>
_______________________________________
More information about the Python-bugs-list
mailing list