diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/methodobject.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c index ca21a68..55a7d6a 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -159,6 +159,26 @@ meth_dealloc(PyCFunctionObject *m) } } +static PyObject * +meth_reduce(PyCFunctionObject *m) +{ + PyObject *builtins; + PyObject *getattr; + _Py_IDENTIFIER(getattr); + + if (m->m_self == NULL || PyModule_Check(m->m_self)) + return PyUnicode_FromString(m->m_ml->ml_name); + + builtins = PyEval_GetBuiltins(); + getattr = _PyDict_GetItemId(builtins, &PyId_getattr); + return Py_BuildValue("O(Os)", getattr, m->m_self, m->m_ml->ml_name); +} + +static PyMethodDef meth_methods[] = { + {"__reduce__", (PyCFunction)meth_reduce, METH_NOARGS, NULL}, + {NULL, NULL} +}; + /* * finds the docstring's introspection signature. * if present, returns a pointer pointing to the first '('. @@ -394,7 +414,7 @@ PyTypeObject PyCFunction_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + meth_methods, /* tp_methods */ meth_members, /* tp_members */ meth_getsets, /* tp_getset */ 0, /* tp_base */ |