summaryrefslogtreecommitdiff
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorAmmar Askar <ammar@ammaraskar.com>2020-04-14 23:36:08 -0700
committerGitHub <noreply@github.com>2020-04-14 23:36:08 -0700
commita86b522d8f1c8b9c26b5550de221d2227158cf4d (patch)
tree58a8be3453359c4847834d7ed8f6409eb129a96a /Modules/_collectionsmodule.c
parent4f98f465f14e7258c5b18a62c5aa114dbe1174d8 (diff)
downloadcpython-git-a86b522d8f1c8b9c26b5550de221d2227158cf4d.tar.gz
bpo-40277: Add a repr() to namedtuple's _tuplegetter to aid with introspection (GH-19537)
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 978ea03bd9..7120e4dda0 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -2493,6 +2493,14 @@ tuplegetter_reduce(_tuplegetterobject *self, PyObject *Py_UNUSED(ignored))
return Py_BuildValue("(O(nO))", (PyObject*) Py_TYPE(self), self->index, self->doc);
}
+static PyObject*
+tuplegetter_repr(_tuplegetterobject *self)
+{
+ return PyUnicode_FromFormat("%s(%zd, %R)",
+ _PyType_Name(Py_TYPE(self)),
+ self->index, self->doc);
+}
+
static PyMemberDef tuplegetter_members[] = {
{"__doc__", T_OBJECT, offsetof(_tuplegetterobject, doc), 0},
@@ -2515,7 +2523,7 @@ static PyTypeObject tuplegetter_type = {
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
- 0, /* tp_repr */
+ (reprfunc)tuplegetter_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */