mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
rejects builtin types with not defined __new__. Added tests for non-pickleable types.
This commit is contained in:
parent
a9dcdabccb
commit
d7a4415599
6 changed files with 78 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue