Issue #24164: Objects that need calling `__new__` with keyword arguments,

can now be pickled using pickle protocols older than protocol version 4.
This commit is contained in:
Serhiy Storchaka 2015-10-10 22:42:18 +03:00
parent 4e96df3b59
commit 0d554d7ef1
6 changed files with 97 additions and 32 deletions

View file

@ -4101,7 +4101,7 @@ _PyObject_GetItemsIter(PyObject *obj, PyObject **listitems,
}
static PyObject *
reduce_newobj(PyObject *obj, int proto)
reduce_newobj(PyObject *obj)
{
PyObject *args = NULL, *kwargs = NULL;
PyObject *copyreg;
@ -4153,7 +4153,7 @@ reduce_newobj(PyObject *obj, int proto)
}
Py_DECREF(args);
}
else if (proto >= 4) {
else {
_Py_IDENTIFIER(__newobj_ex__);
newobj = _PyObject_GetAttrId(copyreg, &PyId___newobj_ex__);
@ -4171,16 +4171,6 @@ reduce_newobj(PyObject *obj, int proto)
return NULL;
}
}
else {
PyErr_SetString(PyExc_ValueError,
"must use protocol 4 or greater to copy this "
"object; since __getnewargs_ex__ returned "
"keyword arguments.");
Py_DECREF(args);
Py_DECREF(kwargs);
Py_DECREF(copyreg);
return NULL;
}
state = _PyObject_GetState(obj);
if (state == NULL) {
@ -4225,7 +4215,7 @@ _common_reduce(PyObject *self, int proto)
PyObject *copyreg, *res;
if (proto >= 2)
return reduce_newobj(self, proto);
return reduce_newobj(self);
copyreg = import_copyreg();
if (!copyreg)