2
2
[out]
3
3
4
4
[case testAssignmentAndVarDef]
5
- a = None # type : A
6
- b = None # type : B
5
+ a: A
6
+ b: B
7
7
if int():
8
8
a = a
9
9
if int():
@@ -17,23 +17,23 @@ class A:
17
17
class B:
18
18
def __init__(self): pass
19
19
20
- x = None # type : A
20
+ x: A
21
21
x = A()
22
22
if int():
23
23
x = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
24
24
[case testInheritInitFromObject]
25
25
class A(object): pass
26
26
class B(object): pass
27
- x = None # type : A
27
+ x: A
28
28
if int():
29
29
x = A()
30
30
if int():
31
31
x = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
32
32
[case testImplicitInheritInitFromObject]
33
33
class A: pass
34
34
class B: pass
35
- x = None # type : A
36
- o = None # type : object
35
+ x: A
36
+ o: object
37
37
if int():
38
38
x = o # E: Incompatible types in assignment (expression has type "object", variable has type "A")
39
39
if int():
@@ -59,7 +59,7 @@ x = B() # type: A
59
59
y = A() # type: B # E: Incompatible types in assignment (expression has type "A", variable has type "B")
60
60
[case testDeclaredVariableInParentheses]
61
61
62
- (x) = None # type: int
62
+ (x) = 2 # type: int
63
63
if int():
64
64
x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
65
65
if int():
@@ -135,8 +135,8 @@ main:6: error: Missing positional arguments "baz", "bas" in call to "foo"
135
135
136
136
[case testLocalVariables]
137
137
def f() -> None:
138
- x = None # type : A
139
- y = None # type : B
138
+ x: A
139
+ y: B
140
140
if int():
141
141
x = x
142
142
x = y # E: Incompatible types in assignment (expression has type "B", variable has type "A")
@@ -229,21 +229,21 @@ reveal_type(__annotations__) # N: Revealed type is "builtins.dict[builtins.str,
229
229
[case testLocalVariableShadowing]
230
230
class A: pass
231
231
class B: pass
232
- a = None # type : A
232
+ a: A
233
233
if int():
234
234
a = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
235
235
a = A()
236
236
def f() -> None:
237
- a = None # type : B
237
+ a: B
238
238
if int():
239
239
a = A() # E: Incompatible types in assignment (expression has type "A", variable has type "B")
240
240
a = B()
241
241
a = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
242
242
a = A()
243
243
[case testGlobalDefinedInBlockWithType]
244
244
class A: pass
245
- while A :
246
- a = None # type : A
245
+ while 1 :
246
+ a: A
247
247
if int():
248
248
a = A()
249
249
a = object() # E: Incompatible types in assignment (expression has type "object", variable has type "A")
0 commit comments