bpo-29914: Fix default implementations of __reduce__ and __reduce_ex_… · pythoncapi/cpython@205e00c · GitHub
Skip to content

Commit 205e00c

Browse files
bpo-29914: Fix default implementations of __reduce__ and __reduce_ex__(). (python#843)
object.__reduce__() no longer takes arguments, object.__reduce_ex__() now requires one argument.
1 parent dd9a0a1 commit 205e00c

4 files changed

Lines changed: 34 additions & 39 deletions

File tree

Lib/test/test_descr.py

Lines changed: 14 additions & 1 deletion

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.7.0 alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- bpo-29914: Fixed default implementations of __reduce__ and __reduce_ex__().
14+
object.__reduce__() no longer takes arguments, object.__reduce_ex__() now
15+
requires one argument.
16+
1317
- bpo-29949: Fix memory usage regression of set and frozenset object.
1418

1519
- bpo-29935: Fixed error messages in the index() method of tuple, list and deque

Objects/clinic/typeobject.c.h

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -131,61 +131,42 @@ type___sizeof__(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
131131
}
132132

133133
PyDoc_STRVAR(object___reduce____doc__,
134-
"__reduce__($self, protocol=0, /)\n"
134+
"__reduce__($self, /)\n"
135135
"--\n"
136136
"\n"
137137
"Helper for pickle.");
138138

139139
#define OBJECT___REDUCE___METHODDEF \
140-
{"__reduce__", (PyCFunction)object___reduce__, METH_FASTCALL, object___reduce____doc__},
140+
{"__reduce__", (PyCFunction)object___reduce__, METH_NOARGS, object___reduce____doc__},
141141

142142
static PyObject *
143-
object___reduce___impl(PyObject *self, int protocol);
143+
object___reduce___impl(PyObject *self);
144144

145145
static PyObject *
146-
object___reduce__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
146+
object___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
147147
{
148-
PyObject *return_value = NULL;
149-
int protocol = 0;
150-
151-
if (!_PyArg_ParseStack(args, nargs, "|i:__reduce__",
152-
&protocol)) {
153-
goto exit;
154-
}
155-
156-
if (!_PyArg_NoStackKeywords("__reduce__", kwnames)) {
157-
goto exit;
158-
}
159-
return_value = object___reduce___impl(self, protocol);
160-
161-
exit:
162-
return return_value;
148+
return object___reduce___impl(self);
163149
}
164150

165151
PyDoc_STRVAR(object___reduce_ex____doc__,
166-
"__reduce_ex__($self, protocol=0, /)\n"
152+
"__reduce_ex__($self, protocol, /)\n"
167153
"--\n"
168154
"\n"
169155
"Helper for pickle.");
170156

171157
#define OBJECT___REDUCE_EX___METHODDEF \
172-
{"__reduce_ex__", (PyCFunction)object___reduce_ex__, METH_FASTCALL, object___reduce_ex____doc__},
158+
{"__reduce_ex__", (PyCFunction)object___reduce_ex__, METH_O, object___reduce_ex____doc__},
173159

174160
static PyObject *
175161
object___reduce_ex___impl(PyObject *self, int protocol);
176162

177163
static PyObject *
178-
object___reduce_ex__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
164+
object___reduce_ex__(PyObject *self, PyObject *arg)
179165
{
180166
PyObject *return_value = NULL;
181-
int protocol = 0;
182-
183-
if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__",
184-
&protocol)) {
185-
goto exit;
186-
}
167+
int protocol;
187168

188-
if (!_PyArg_NoStackKeywords("__reduce_ex__", kwnames)) {
169+
if (!PyArg_Parse(arg, "i:__reduce_ex__", &protocol)) {
189170
goto exit;
190171
}
191172
return_value = object___reduce_ex___impl(self, protocol);
@@ -256,4 +237,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
256237
{
257238
return object___dir___impl(self);
258239
}
259-
/*[clinic end generated code: output=ce354e436e2360a0 input=a9049054013a1b77]*/
240+
/*[clinic end generated code: output=8c4c856859564eaa input=a9049054013a1b77]*/

Objects/typeobject.c

Lines changed: 5 additions & 8 deletions

0 commit comments

Comments
 (0)