22from collections import namedtuple
33
44X = namedtuple('X', 'x y')
5- x = None # type : X
5+ x: X
66a, b = x
77b = x[0]
88a = x[1]
@@ -14,7 +14,7 @@ x[2] # E: Tuple index out of range
1414from collections import namedtuple
1515
1616X = namedtuple('X', ('x', 'y'))
17- x = None # type : X
17+ x: X
1818a, b = x
1919b = x[0]
2020a = x[1]
@@ -32,7 +32,7 @@ X = namedtuple('X', 'x, _y, _z') # E: "namedtuple()" field names cannot start w
3232from collections import namedtuple
3333
3434X = namedtuple('X', 'x y')
35- x = None # type : X
35+ x: X
3636x.x
3737x.y
3838x.z # E: "X" has no attribute "z"
@@ -63,13 +63,13 @@ class A(NamedTuple):
6363from collections import namedtuple
6464
6565X = namedtuple('X', 'x y')
66- x = None # type : X
66+ x: X
6767x.x = 5 # E: Property "x" defined in "X" is read-only
6868x.y = 5 # E: Property "y" defined in "X" is read-only
6969x.z = 5 # E: "X" has no attribute "z"
7070
7171class A(X): pass
72- a = None # type : A
72+ a: A
7373a.x = 5 # E: Property "x" defined in "X" is read-only
7474a.y = 5 # E: Property "y" defined in "X" is read-only
7575-- a.z = 5 # not supported yet
@@ -292,7 +292,7 @@ A = NamedTuple('A', [('a', int), ('b', str)])
292292class B(A): pass
293293a = A(1, '')
294294b = B(1, '')
295- t = None # type : Tuple[int, str]
295+ t: Tuple[int, str]
296296if int():
297297 b = a # E: Incompatible types in assignment (expression has type "A", variable has type "B")
298298if int():
@@ -357,7 +357,7 @@ C(2).b
357357from collections import namedtuple
358358
359359X = namedtuple('X', ['x', 'y'])
360- x = None # type : X
360+ x: X
361361reveal_type(x._asdict()) # N: Revealed type is "builtins.dict[builtins.str, Any]"
362362
363363[builtins fixtures/dict.pyi]
@@ -366,7 +366,7 @@ reveal_type(x._asdict()) # N: Revealed type is "builtins.dict[builtins.str, Any
366366from collections import namedtuple
367367
368368X = namedtuple('X', ['x', 'y'])
369- x = None # type : X
369+ x: X
370370reveal_type(x._replace()) # N: Revealed type is "Tuple[Any, Any, fallback=__main__.X]"
371371x._replace(y=5)
372372x._replace(x=3)
@@ -391,7 +391,7 @@ X._replace(x=1, y=2) # E: Missing positional argument "_self" in call to "_repl
391391from typing import NamedTuple
392392
393393X = NamedTuple('X', [('x', int), ('y', str)])
394- x = None # type : X
394+ x: X
395395reveal_type(x._replace()) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]"
396396x._replace(x=5)
397397x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "int"; expected "str"
@@ -405,7 +405,7 @@ reveal_type(X._make([5, 'a'])) # N: Revealed type is "Tuple[builtins.int, built
405405X._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; expected "Iterable[Any]"
406406
407407-- # FIX: not a proper class method
408- -- x = None # type : X
408+ -- x: X
409409-- reveal_type(x._make([5, 'a'])) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]"
410410-- x._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; expected Iterable[Any]
411411
@@ -423,7 +423,7 @@ from typing import NamedTuple
423423
424424X = NamedTuple('X', [('x', int), ('y', str)])
425425reveal_type(X._source) # N: Revealed type is "builtins.str"
426- x = None # type : X
426+ x: X
427427reveal_type(x._source) # N: Revealed type is "builtins.str"
428428[builtins fixtures/tuple.pyi]
429429
@@ -459,7 +459,7 @@ from typing import NamedTuple
459459
460460X = NamedTuple('X', [('x', int), ('y', str)])
461461reveal_type(X._field_types) # N: Revealed type is "builtins.dict[builtins.str, Any]"
462- x = None # type : X
462+ x: X
463463reveal_type(x._field_types) # N: Revealed type is "builtins.dict[builtins.str, Any]"
464464
465465[builtins fixtures/dict.pyi]
@@ -472,7 +472,7 @@ def f(x: A) -> None: pass
472472
473473class B(NamedTuple('B', []), A): pass
474474f(B())
475- x = None # type : A
475+ x: A
476476if int():
477477 x = B()
478478
@@ -482,7 +482,7 @@ def g(x: C) -> None: pass
482482class D(NamedTuple('D', []), A): pass
483483
484484g(D()) # E: Argument 1 to "g" has incompatible type "D"; expected "C"
485- y = None # type : C
485+ y: C
486486if int():
487487 y = D() # E: Incompatible types in assignment (expression has type "D", variable has type "C")
488488[builtins fixtures/tuple.pyi]
@@ -499,9 +499,9 @@ class A(NamedTuple('A', [('x', str)])):
499499class B(A):
500500 pass
501501
502- a = None # type : A
502+ a: A
503503a = A('').member()
504- b = None # type : B
504+ b: B
505505b = B('').member()
506506a = B('')
507507a = B('').member()
@@ -511,14 +511,14 @@ a = B('').member()
511511from typing import NamedTuple, TypeVar
512512A = NamedTuple('A', [('x', str)])
513513reveal_type(A('hello')._replace(x='')) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.A]"
514- a = None # type : A
514+ a: A
515515a = A('hello')._replace(x='')
516516
517517class B(A):
518518 pass
519519
520520reveal_type(B('hello')._replace(x='')) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.B]"
521- b = None # type : B
521+ b: B
522522b = B('hello')._replace(x='')
523523[builtins fixtures/tuple.pyi]
524524
0 commit comments