[issue5180] 3.1 cannot unpickle 2.7-created pickle
report at bugs.python.org
Thu Jul 15 19:50:05 CEST 2010
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
I think I have found a better solution. Since we are dealing with classic classes, they should not define __new__. If in porting to 3.x, users introduce __new__ that requires arguments, they will not be able to unpickle 2.x pickles no matter what we do.
Therefore, I propose to replace _EmptyClass trick in pickle.py with a call to klass.__new__:
- value = _EmptyClass()
- value.__class__ = klass
+ value = klass.__new__(klass)
and do the same in _pickle.c's instantiate:
r = PyObject_CallMethod(cls, "__new__", "O", cls);
Note that I am not even calling tp_new here directly, so all the hoops in tp_new_wrapper get jumped through.
The advantage of this scheme is that python and C code will work exactly the same and users that have corner cases for which the scheme does not work will be able to figure out what is going on by looking at the python code.
Added file: http://bugs.python.org/file18017/issue5180a.diff
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list