mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
gh-92107: Add tests that subscription works on arbitrary named tuple types (GH-92304)
This commit is contained in:
parent
000a072318
commit
9d20e1af40
2 changed files with 26 additions and 0 deletions
|
|
@ -698,6 +698,18 @@ class TestNamedTuple(unittest.TestCase):
|
|||
Point = namedtuple('Point', 'x y')
|
||||
self.assertEqual(Point.__match_args__, ('x', 'y'))
|
||||
|
||||
def test_non_generic_subscript(self):
|
||||
# For backward compatibility, subscription works
|
||||
# on arbitrary named tuple types.
|
||||
Group = collections.namedtuple('Group', 'key group')
|
||||
A = Group[int, list[int]]
|
||||
self.assertEqual(A.__origin__, Group)
|
||||
self.assertEqual(A.__parameters__, ())
|
||||
self.assertEqual(A.__args__, (int, list[int]))
|
||||
a = A(1, [2])
|
||||
self.assertIs(type(a), Group)
|
||||
self.assertEqual(a, (1, [2]))
|
||||
|
||||
|
||||
################################################################################
|
||||
### Abstract Base Classes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue