You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test-data/unit/pythoneval.test
+26Lines changed: 26 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1390,6 +1390,32 @@ x = X(a=1, b='s')
1390
1390
[out]
1391
1391
_testNamedTupleNew.py:12: note: Revealed type is "Tuple[builtins.int, fallback=_testNamedTupleNew.Child]"
1392
1392
1393
+
[case testNamedTupleTypeInheritanceSpecialCase]
1394
+
from typing import NamedTuple, Tuple
1395
+
from collections import namedtuple
1396
+
1397
+
A = NamedTuple('A', [('param', int)])
1398
+
B = namedtuple('B', ['param'])
1399
+
1400
+
def accepts_named_tuple(arg: NamedTuple):
1401
+
reveal_type(arg._asdict())
1402
+
reveal_type(arg._fields)
1403
+
reveal_type(arg._field_defaults)
1404
+
1405
+
a = A(1)
1406
+
b = B(1)
1407
+
1408
+
accepts_named_tuple(a)
1409
+
accepts_named_tuple(b)
1410
+
accepts_named_tuple(1)
1411
+
accepts_named_tuple((1, 2))
1412
+
[out]
1413
+
_testNamedTupleTypeInheritanceSpecialCase.py:8: note: Revealed type is "collections.OrderedDict[builtins.str, Any]"
1414
+
_testNamedTupleTypeInheritanceSpecialCase.py:9: note: Revealed type is "builtins.tuple[builtins.str]"
1415
+
_testNamedTupleTypeInheritanceSpecialCase.py:10: note: Revealed type is "builtins.dict[builtins.str, Any]"
1416
+
_testNamedTupleTypeInheritanceSpecialCase.py:17: error: Argument 1 to "accepts_named_tuple" has incompatible type "int"; expected "NamedTuple"
1417
+
_testNamedTupleTypeInheritanceSpecialCase.py:18: error: Argument 1 to "accepts_named_tuple" has incompatible type "Tuple[int, int]"; expected "NamedTuple"
0 commit comments