Alexander Belopolsky <belopol...@users.sourceforge.net> added the comment:

Antoine,

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.

Attaching issue5180a.diff

----------
Added file: http://bugs.python.org/file18017/issue5180a.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5180>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to