summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-12 09:23:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-12 09:23:04 (GMT)
commitd7a441559921804a5a6141c3ec42f896f8f3b010 (patch)
treeeaeaa693fe1af5871f54222f7d07d7cc49d3dd16 /Objects
parenta9dcdabccb1a1f7c76030c0b188ecaf7ab599e57 (diff)
downloadcpython-d7a441559921804a5a6141c3ec42f896f8f3b010.zip
cpython-d7a441559921804a5a6141c3ec42f896f8f3b010.tar.gz
cpython-d7a441559921804a5a6141c3ec42f896f8f3b010.tar.bz2
Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
rejects builtin types with not defined __new__. Added tests for non-pickleable types.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 09c895c..b38e0fb 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3980,6 +3980,12 @@ reduce_4(PyObject *obj)
PyObject *result;
_Py_IDENTIFIER(__newobj_ex__);
+ if (Py_TYPE(obj)->tp_new == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "can't pickle %s objects",
+ Py_TYPE(obj)->tp_name);
+ return NULL;
+ }
if (_PyObject_GetNewArguments(obj, &args, &kwargs) < 0) {
return NULL;
}
@@ -4046,6 +4052,12 @@ reduce_2(PyObject *obj)
Py_ssize_t i, n;
_Py_IDENTIFIER(__newobj__);
+ if (Py_TYPE(obj)->tp_new == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "can't pickle %s objects",
+ Py_TYPE(obj)->tp_name);
+ return NULL;
+ }
if (_PyObject_GetNewArguments(obj, &args, &kwargs) < 0) {
return NULL;
}