diff options
author | Ammar Askar <ammar@ammaraskar.com> | 2020-04-14 23:36:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-14 23:36:08 -0700 |
commit | a86b522d8f1c8b9c26b5550de221d2227158cf4d (patch) | |
tree | 58a8be3453359c4847834d7ed8f6409eb129a96a /Lib/test | |
parent | 4f98f465f14e7258c5b18a62c5aa114dbe1174d8 (diff) | |
download | cpython-git-a86b522d8f1c8b9c26b5550de221d2227158cf4d.tar.gz |
bpo-40277: Add a repr() to namedtuple's _tuplegetter to aid with introspection (GH-19537)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_collections.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 0207823f5a..a8d3337ef5 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -411,6 +411,18 @@ class TestNamedTuple(unittest.TestCase): 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 |