summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-12 11:59:03 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-12 11:59:03 +0200
commitfedcf9474e73a8cb209a61f513f46fb062f2cd11 (patch)
tree8b5cfe5db62251925f320e1be9226e80bbe564d0
parent76e6cc15b26e58685084497c869decd2a5275b21 (diff)
downloadcpython-fedcf9474e73a8cb209a61f513f46fb062f2cd11.tar.gz
cpython-fedcf9474e73a8cb209a61f513f46fb062f2cd11.zip
Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
rejects builtin types with not defined __new__.
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c7
2 files changed, 10 insertions, 0 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 03aac95da48..e9251039d25 100644
--- 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).
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index d3e5384a6d3..720a84e97e0 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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);