]> granicus.if.org Git - python/commitdiff
Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 12 Nov 2015 09:59:03 +0000 (11:59 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 12 Nov 2015 09:59:03 +0000 (11:59 +0200)
rejects builtin types with not defined __new__.

Misc/NEWS
Objects/typeobject.c

index 03aac95da48df1855bc4e37f56c51a250dc15a37..e9251039d2580b7044a40fd58b9217a03c0001c3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.7.11?
 Core and Builtins
 -----------------
 
+- Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
+  rejects builtin types with not defined __new__.
+
 - Issue #7267: format(int, 'c') now raises OverflowError when the argument is
   not in range(0, 256).
 
index d3e5384a6d3f624cc4d5d57a3e9751774e625469..720a84e97e0d44a6a3ca8c0bad6d8102e755b4f5 100644 (file)
@@ -3214,6 +3214,13 @@ reduce_2(PyObject *obj)
     if (cls == NULL)
         return NULL;
 
+    if (PyType_Check(cls) && ((PyTypeObject *)cls)->tp_new == NULL) {
+        PyErr_Format(PyExc_TypeError,
+                     "can't pickle %s objects",
+                     ((PyTypeObject *)cls)->tp_name);
+        return NULL;
+    }
+
     getnewargs = PyObject_GetAttrString(obj, "__getnewargs__");
     if (getnewargs != NULL) {
         args = PyObject_CallObject(getnewargs, NULL);