Make Ellipsis and NotImplemented picklable through the reduce protocol. · pythoncapi/cpython@c49477b · GitHub
Skip to content

Commit c49477b

Browse files
committed
Make Ellipsis and NotImplemented picklable through the reduce protocol.
1 parent 4c05d3b commit c49477b

4 files changed

Lines changed: 24 additions & 42 deletions

File tree

Lib/pickle.py

Lines changed: 0 additions & 8 deletions

Modules/_pickle.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,30 +3171,6 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name)
31713171
return status;
31723172
}
31733173

3174-
static int
3175-
save_ellipsis(PicklerObject *self, PyObject *obj)
3176-
{
3177-
PyObject *str = PyUnicode_FromString("Ellipsis");
3178-
int res;
3179-
if (str == NULL)
3180-
return -1;
3181-
res = save_global(self, Py_Ellipsis, str);
3182-
Py_DECREF(str);
3183-
return res;
3184-
}
3185-
3186-
static int
3187-
save_notimplemented(PicklerObject *self, PyObject *obj)
3188-
{
3189-
PyObject *str = PyUnicode_FromString("NotImplemented");
3190-
int res;
3191-
if (str == NULL)
3192-
return -1;
3193-
res = save_global(self, Py_NotImplemented, str);
3194-
Py_DECREF(str);
3195-
return res;
3196-
}
3197-
31983174
static int
31993175
save_pers(PicklerObject *self, PyObject *obj, PyObject *func)
32003176
{
@@ -3552,14 +3528,6 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
35523528
status = save_none(self, obj);
35533529
goto done;
35543530
}
3555-
else if (obj == Py_Ellipsis) {
3556-
status = save_ellipsis(self, obj);
3557-
goto done;
3558-
}
3559-
else if (obj == Py_NotImplemented) {
3560-
status = save_notimplemented(self, obj);
3561-
goto done;
3562-
}
35633531
else if (obj == Py_False || obj == Py_True) {
35643532
status = save_bool(self, obj);
35653533
goto done;

Objects/object.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,17 @@ NotImplemented_repr(PyObject *op)
14641464
return PyUnicode_FromString("NotImplemented");
14651465
}
14661466

1467+
static PyObject *
1468+
NotImplemented_reduce(PyObject *op)
1469+
{
1470+
return PyUnicode_FromString("NotImplemented");
1471+
}
1472+
1473+
static PyMethodDef notimplemented_methods[] = {
1474+
{"__reduce__", (PyCFunction)NotImplemented_reduce, METH_NOARGS, NULL},
1475+
{NULL, NULL}
1476+
};
1477+
14671478
static PyObject *
14681479
notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
14691480
{
@@ -1511,7 +1522,7 @@ static PyTypeObject PyNotImplemented_Type = {
15111522
0, /*tp_weaklistoffset */
15121523
0, /*tp_iter */
15131524
0, /*tp_iternext */
1514-
0, /*tp_methods */
1525+
notimplemented_methods, /*tp_methods */
15151526
0, /*tp_members */
15161527
0, /*tp_getset */
15171528
0, /*tp_base */

Objects/sliceobject.c

Lines changed: 12 additions & 1 deletion

0 commit comments

Comments
 (0)