mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-118285: Fix signatures of operator.{attrgetter,itemgetter,methodcaller} instances (GH-118316)
* Allow to specify the signature of custom callable instances of extension type by the __text_signature__ attribute. * Specify signatures of operator.attrgetter, operator.itemgetter, and operator.methodcaller instances.
This commit is contained in:
parent
51c70de998
commit
444ac0b7a6
6 changed files with 76 additions and 5 deletions
|
|
@ -966,6 +966,18 @@ static struct PyMethodDef operator_methods[] = {
|
|||
|
||||
};
|
||||
|
||||
|
||||
static PyObject *
|
||||
text_signature(PyObject *self, void *Py_UNUSED(ignored))
|
||||
{
|
||||
return PyUnicode_FromString("(obj, /)");
|
||||
}
|
||||
|
||||
static PyGetSetDef common_getset[] = {
|
||||
{"__text_signature__", text_signature, (setter)NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
/* itemgetter object **********************************************************/
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -1171,6 +1183,7 @@ static PyType_Slot itemgetter_type_slots[] = {
|
|||
{Py_tp_clear, itemgetter_clear},
|
||||
{Py_tp_methods, itemgetter_methods},
|
||||
{Py_tp_members, itemgetter_members},
|
||||
{Py_tp_getset, common_getset},
|
||||
{Py_tp_new, itemgetter_new},
|
||||
{Py_tp_getattro, PyObject_GenericGetAttr},
|
||||
{Py_tp_repr, itemgetter_repr},
|
||||
|
|
@ -1528,6 +1541,7 @@ static PyType_Slot attrgetter_type_slots[] = {
|
|||
{Py_tp_clear, attrgetter_clear},
|
||||
{Py_tp_methods, attrgetter_methods},
|
||||
{Py_tp_members, attrgetter_members},
|
||||
{Py_tp_getset, common_getset},
|
||||
{Py_tp_new, attrgetter_new},
|
||||
{Py_tp_getattro, PyObject_GenericGetAttr},
|
||||
{Py_tp_repr, attrgetter_repr},
|
||||
|
|
@ -1863,6 +1877,7 @@ static PyType_Slot methodcaller_type_slots[] = {
|
|||
{Py_tp_clear, methodcaller_clear},
|
||||
{Py_tp_methods, methodcaller_methods},
|
||||
{Py_tp_members, methodcaller_members},
|
||||
{Py_tp_getset, common_getset},
|
||||
{Py_tp_new, methodcaller_new},
|
||||
{Py_tp_getattro, PyObject_GenericGetAttr},
|
||||
{Py_tp_repr, methodcaller_repr},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue