(original) (raw)
changeset: 99078:2b950eba9792 branch: 2.7 user: Serhiy Storchaka storchaka@gmail.com date: Thu Nov 12 11:59:03 2015 +0200 files: Misc/NEWS Objects/typeobject.c description: Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now rejects builtin types with not defined __new__. diff -r 94664fb4354e -r 2b950eba9792 Misc/NEWS --- a/Misc/NEWS Thu Nov 12 11:36:42 2015 +0200 +++ b/Misc/NEWS Thu Nov 12 11:59:03 2015 +0200 @@ -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 -r 94664fb4354e -r 2b950eba9792 Objects/typeobject.c --- a/Objects/typeobject.c Thu Nov 12 11:36:42 2015 +0200 +++ b/Objects/typeobject.c Thu Nov 12 11:59:03 2015 +0200 @@ -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); /storchaka@gmail.com