self.assertIs(P.m.__doc__, Q.o.__doc__)
self.assertIs(P.n.__doc__, Q.p.__doc__)
+ @support.cpython_only
+ def test_field_repr(self):
+ Point = namedtuple('Point', 'x y')
+ self.assertEqual(repr(Point.x), "_tuplegetter(0, 'Alias for field number 0')")
+ self.assertEqual(repr(Point.y), "_tuplegetter(1, 'Alias for field number 1')")
+
+ Point.x.__doc__ = 'The x-coordinate'
+ Point.y.__doc__ = 'The y-coordinate'
+
+ self.assertEqual(repr(Point.x), "_tuplegetter(0, 'The x-coordinate')")
+ self.assertEqual(repr(Point.y), "_tuplegetter(1, 'The y-coordinate')")
+
def test_name_fixer(self):
for spec, renamed in [
[('efg', 'g%hi'), ('efg', '_1')], # field with non-alpha char
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},
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 */