diff options
| author | Joe Jevnik <JoeJev@gmail.com> | 2019-02-21 16:00:40 -0500 | 
|---|---|---|
| committer | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-02-21 13:00:40 -0800 | 
| commit | f36f89257b30e0bf88e8aaff6da14a9a96f57b9e (patch) | |
| tree | c8e0d07472981a5cb4fcf4d597178c9a30c06819 /Modules/_collectionsmodule.c | |
| parent | 407c7343266eb3e5a2f5c1f4913082c84f8dd8a0 (diff) | |
| download | cpython-git-f36f89257b30e0bf88e8aaff6da14a9a96f57b9e.tar.gz | |
bpo-36068: Make _tuplegetter objects serializable (GH-11981)
Diffstat (limited to 'Modules/_collectionsmodule.c')
| -rw-r--r-- | Modules/_collectionsmodule.c | 13 | 
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 280b15d73b..1c9e866e62 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -2440,12 +2440,23 @@ tuplegetter_dealloc(_tuplegetterobject *self)      Py_TYPE(self)->tp_free((PyObject*)self);  } +static PyObject* +tuplegetter_reduce(_tuplegetterobject *self) +{ +    return Py_BuildValue("(O(nO))", (PyObject*) Py_TYPE(self), self->index, self->doc); +} +  static PyMemberDef tuplegetter_members[] = {      {"__doc__",  T_OBJECT, offsetof(_tuplegetterobject, doc), 0},      {0}  }; +static PyMethodDef tuplegetter_methods[] = { +    {"__reduce__", (PyCFunction) tuplegetter_reduce, METH_NOARGS, NULL}, +    {NULL}, +}; +  static PyTypeObject tuplegetter_type = {      PyVarObject_HEAD_INIT(NULL, 0)      "_collections._tuplegetter",                /* tp_name */ @@ -2475,7 +2486,7 @@ static PyTypeObject tuplegetter_type = {      0,                                          /* tp_weaklistoffset */      0,                                          /* tp_iter */      0,                                          /* tp_iternext */ -    0,                                          /* tp_methods */ +    tuplegetter_methods,                        /* tp_methods */      tuplegetter_members,                        /* tp_members */      0,                                          /* tp_getset */      0,                                          /* tp_base */  | 
