@@ -938,8 +938,9 @@ class A:
938938 def __init__(self) -> None:
939939 self.b = NamedTuple('x', [('s', str), ('n', int)]) # E: NamedTuple type as an attribute is not supported
940940
941- reveal_type(A().b) # N: Revealed type is "Any "
941+ reveal_type(A().b) # N: Revealed type is "typing.NamedTuple "
942942[builtins fixtures/tuple.pyi]
943+ [typing fixtures/typing-namedtuple.pyi]
943944
944945[case testNamedTupleWrongfile]
945946from typing import NamedTuple
@@ -983,7 +984,7 @@ class Both2(Other, Bar): ...
983984class Both3(Biz, Other): ...
984985
985986def print_namedtuple(obj: NamedTuple) -> None:
986- reveal_type(obj.name ) # N: Revealed type is "builtins.str"
987+ reveal_type(obj._fields ) # N: Revealed type is "builtins.tuple[builtins. str, ...] "
987988
988989b1: Bar
989990b2: Baz
@@ -1337,3 +1338,12 @@ class SNT(NT[int]): ...
13371338reveal_type(SNT("test", 42).meth()) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.SNT]"
13381339[builtins fixtures/tuple.pyi]
13391340[typing fixtures/typing-namedtuple.pyi]
1341+
1342+ [case testNoCrashUnsupportedNamedTuple]
1343+ from typing import NamedTuple
1344+ class Test:
1345+ def __init__(self, field) -> None:
1346+ self.Item = NamedTuple("x", [(field, str)]) # E: NamedTuple type as an attribute is not supported
1347+ self.item: self.Item # E: Name "self.Item" is not defined
1348+ [builtins fixtures/tuple.pyi]
1349+ [typing fixtures/typing-namedtuple.pyi]
0 commit comments