[Python-checkins] cpython (2.7): Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now

serhiy.storchaka python-checkins at python.org
Thu Nov 12 05:01:06 EST 2015


https://hg.python.org/cpython/rev/2b950eba9792
changeset:   99078:2b950eba9792
branch:      2.7
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Nov 12 11:59:03 2015 +0200
summary:
  Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
rejects builtin types with not defined __new__.

files:
  Misc/NEWS            |  3 +++
  Objects/typeobject.c |  7 +++++++
  2 files changed, 10 insertions(+), 0 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 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).
 
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3214,6 +3214,13 @@
     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);

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list