2
2
from collections import namedtuple
3
3
4
4
X = namedtuple('X', 'x y')
5
- x = None # type : X
5
+ x: X
6
6
a, b = x
7
7
b = x[0]
8
8
a = x[1]
@@ -14,7 +14,7 @@ x[2] # E: Tuple index out of range
14
14
from collections import namedtuple
15
15
16
16
X = namedtuple('X', ('x', 'y'))
17
- x = None # type : X
17
+ x: X
18
18
a, b = x
19
19
b = x[0]
20
20
a = x[1]
@@ -32,7 +32,7 @@ X = namedtuple('X', 'x, _y, _z') # E: "namedtuple()" field names cannot start w
32
32
from collections import namedtuple
33
33
34
34
X = namedtuple('X', 'x y')
35
- x = None # type : X
35
+ x: X
36
36
x.x
37
37
x.y
38
38
x.z # E: "X" has no attribute "z"
@@ -63,13 +63,13 @@ class A(NamedTuple):
63
63
from collections import namedtuple
64
64
65
65
X = namedtuple('X', 'x y')
66
- x = None # type : X
66
+ x: X
67
67
x.x = 5 # E: Property "x" defined in "X" is read-only
68
68
x.y = 5 # E: Property "y" defined in "X" is read-only
69
69
x.z = 5 # E: "X" has no attribute "z"
70
70
71
71
class A(X): pass
72
- a = None # type : A
72
+ a: A
73
73
a.x = 5 # E: Property "x" defined in "X" is read-only
74
74
a.y = 5 # E: Property "y" defined in "X" is read-only
75
75
-- a.z = 5 # not supported yet
@@ -292,7 +292,7 @@ A = NamedTuple('A', [('a', int), ('b', str)])
292
292
class B(A): pass
293
293
a = A(1, '')
294
294
b = B(1, '')
295
- t = None # type : Tuple[int, str]
295
+ t: Tuple[int, str]
296
296
if int():
297
297
b = a # E: Incompatible types in assignment (expression has type "A", variable has type "B")
298
298
if int():
@@ -357,7 +357,7 @@ C(2).b
357
357
from collections import namedtuple
358
358
359
359
X = namedtuple('X', ['x', 'y'])
360
- x = None # type : X
360
+ x: X
361
361
reveal_type(x._asdict()) # N: Revealed type is "builtins.dict[builtins.str, Any]"
362
362
363
363
[builtins fixtures/dict.pyi]
@@ -366,7 +366,7 @@ reveal_type(x._asdict()) # N: Revealed type is "builtins.dict[builtins.str, Any
366
366
from collections import namedtuple
367
367
368
368
X = namedtuple('X', ['x', 'y'])
369
- x = None # type : X
369
+ x: X
370
370
reveal_type(x._replace()) # N: Revealed type is "Tuple[Any, Any, fallback=__main__.X]"
371
371
x._replace(y=5)
372
372
x._replace(x=3)
@@ -391,7 +391,7 @@ X._replace(x=1, y=2) # E: Missing positional argument "_self" in call to "_repl
391
391
from typing import NamedTuple
392
392
393
393
X = NamedTuple('X', [('x', int), ('y', str)])
394
- x = None # type : X
394
+ x: X
395
395
reveal_type(x._replace()) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]"
396
396
x._replace(x=5)
397
397
x._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
405
405
X._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; expected "Iterable[Any]"
406
406
407
407
-- # FIX: not a proper class method
408
- -- x = None # type : X
408
+ -- x: X
409
409
-- reveal_type(x._make([5, 'a'])) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]"
410
410
-- x._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; expected Iterable[Any]
411
411
@@ -423,7 +423,7 @@ from typing import NamedTuple
423
423
424
424
X = NamedTuple('X', [('x', int), ('y', str)])
425
425
reveal_type(X._source) # N: Revealed type is "builtins.str"
426
- x = None # type : X
426
+ x: X
427
427
reveal_type(x._source) # N: Revealed type is "builtins.str"
428
428
[builtins fixtures/tuple.pyi]
429
429
@@ -459,7 +459,7 @@ from typing import NamedTuple
459
459
460
460
X = NamedTuple('X', [('x', int), ('y', str)])
461
461
reveal_type(X._field_types) # N: Revealed type is "builtins.dict[builtins.str, Any]"
462
- x = None # type : X
462
+ x: X
463
463
reveal_type(x._field_types) # N: Revealed type is "builtins.dict[builtins.str, Any]"
464
464
465
465
[builtins fixtures/dict.pyi]
@@ -472,7 +472,7 @@ def f(x: A) -> None: pass
472
472
473
473
class B(NamedTuple('B', []), A): pass
474
474
f(B())
475
- x = None # type : A
475
+ x: A
476
476
if int():
477
477
x = B()
478
478
@@ -482,7 +482,7 @@ def g(x: C) -> None: pass
482
482
class D(NamedTuple('D', []), A): pass
483
483
484
484
g(D()) # E: Argument 1 to "g" has incompatible type "D"; expected "C"
485
- y = None # type : C
485
+ y: C
486
486
if int():
487
487
y = D() # E: Incompatible types in assignment (expression has type "D", variable has type "C")
488
488
[builtins fixtures/tuple.pyi]
@@ -499,9 +499,9 @@ class A(NamedTuple('A', [('x', str)])):
499
499
class B(A):
500
500
pass
501
501
502
- a = None # type : A
502
+ a: A
503
503
a = A('').member()
504
- b = None # type : B
504
+ b: B
505
505
b = B('').member()
506
506
a = B('')
507
507
a = B('').member()
@@ -511,14 +511,14 @@ a = B('').member()
511
511
from typing import NamedTuple, TypeVar
512
512
A = NamedTuple('A', [('x', str)])
513
513
reveal_type(A('hello')._replace(x='')) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.A]"
514
- a = None # type : A
514
+ a: A
515
515
a = A('hello')._replace(x='')
516
516
517
517
class B(A):
518
518
pass
519
519
520
520
reveal_type(B('hello')._replace(x='')) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.B]"
521
- b = None # type : B
521
+ b: B
522
522
b = B('hello')._replace(x='')
523
523
[builtins fixtures/tuple.pyi]
524
524
0 commit comments