This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients alexandre.vassalotti, belopolsky, lemburg, mark.dickinson, pitrou
Date 2010-07-15.17:50:00
SpamBayes Score 0.0019948932
Marked as misclassified No
Message-id <>

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 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
Date User Action Args
2010-07-15 17:50:07belopolskysetrecipients: + belopolsky, lemburg, mark.dickinson, pitrou, alexandre.vassalotti
2010-07-15 17:50:05belopolskysetmessageid: <>
2010-07-15 17:50:03belopolskylinkissue5180 messages
2010-07-15 17:50:03belopolskycreate