9
9
10
10
from abc import abstractmethod, ABCMeta
11
11
12
- i = None # type : I
13
- j = None # type : J
14
- a = None # type : A
15
- b = None # type : B
16
- c = None # type : C
12
+ i: I
13
+ j: J
14
+ a: A
15
+ b: B
16
+ c: C
17
17
18
18
def f(): i, j, a, b, c # Prevent redefinition
19
19
@@ -44,10 +44,10 @@ class C(I): pass
44
44
45
45
from abc import abstractmethod, ABCMeta
46
46
47
- i = None # type : I
48
- j = None # type : J
49
- a = None # type : A
50
- o = None # type : object
47
+ i: I
48
+ j: J
49
+ a: A
50
+ o: object
51
51
52
52
def f(): i, j, a, o # Prevent redefinition
53
53
@@ -73,9 +73,9 @@ class A(J): pass
73
73
[case testInheritingAbstractClassInSubclass]
74
74
from abc import abstractmethod, ABCMeta
75
75
76
- i = None # type : I
77
- a = None # type : A
78
- b = None # type : B
76
+ i: I
77
+ a: A
78
+ b: B
79
79
80
80
if int():
81
81
i = a # E: Incompatible types in assignment (expression has type "A", variable has type "I")
@@ -106,8 +106,8 @@ class I(metaclass=ABCMeta):
106
106
@abstractmethod
107
107
def f(self): pass
108
108
109
- o = None # type : object
110
- t = None # type : type
109
+ o: object
110
+ t: type
111
111
112
112
o = I
113
113
t = I
@@ -122,8 +122,10 @@ class I(metaclass=ABCMeta):
122
122
class A(I): pass
123
123
class B: pass
124
124
125
- i, a, b = None, None, None # type: (I, A, B)
126
- o = None # type: object
125
+ i: I
126
+ a: A
127
+ b: B
128
+ o: object
127
129
128
130
if int():
129
131
a = cast(I, o) # E: Incompatible types in assignment (expression has type "I", variable has type "A")
@@ -220,6 +222,7 @@ f(GoodAlias)
220
222
[out]
221
223
222
224
[case testInstantiationAbstractsInTypeForVariables]
225
+ # flags: --no-strict-optional
223
226
from typing import Type
224
227
from abc import abstractmethod
225
228
@@ -399,7 +402,9 @@ class I(metaclass=ABCMeta):
399
402
@abstractmethod
400
403
def f(self, a: int) -> str: pass
401
404
402
- i, a, b = None, None, None # type: (I, int, str)
405
+ i: I
406
+ a: int
407
+ b: str
403
408
404
409
if int():
405
410
a = i.f(a) # E: Incompatible types in assignment (expression has type "str", variable has type "int")
@@ -419,7 +424,9 @@ class J(metaclass=ABCMeta):
419
424
def f(self, a: int) -> str: pass
420
425
class I(J): pass
421
426
422
- i, a, b = None, None, None # type: (I, int, str)
427
+ i: I
428
+ a: int
429
+ b: str
423
430
424
431
if int():
425
432
a = i.f(1) # E: Incompatible types in assignment (expression has type "str", variable has type "int")
@@ -505,7 +512,7 @@ class B(metaclass=ABCMeta):
505
512
@abstractmethod
506
513
def g(self) -> None: pass
507
514
class C(A, B): pass
508
- x = None # type : C
515
+ x: C
509
516
x.f()
510
517
x.g()
511
518
x.f(x) # E: Too many arguments for "f" of "A"
@@ -737,6 +744,7 @@ class A(metaclass=ABCMeta):
737
744
def x(self, x: int) -> None: pass
738
745
739
746
[case testReadWriteDeleteAbstractProperty]
747
+ # flags: --no-strict-optional
740
748
from abc import ABC, abstractmethod
741
749
class Abstract(ABC):
742
750
@property
@@ -853,6 +861,7 @@ main:8: error: Cannot instantiate abstract class "B" with abstract attribute "x"
853
861
main:9: error: "int" has no attribute "y"
854
862
855
863
[case testSuperWithAbstractProperty]
864
+ # flags: --no-strict-optional
856
865
from abc import abstractproperty, ABCMeta
857
866
class A(metaclass=ABCMeta):
858
867
@abstractproperty
0 commit comments