Skip to content

Commit fae7d90

Browse files
authored
Enable strict optional for more test files (4) (#15601)
1 parent d4865b2 commit fae7d90

File tree

4 files changed

+99
-95
lines changed

4 files changed

+99
-95
lines changed

mypy/test/testcheck.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151

5252
# TODO: Enable strict optional in test cases by default. Remove files here, once test cases are updated
5353
no_strict_optional_files = {
54-
"check-basic.test",
55-
"check-bound.test",
56-
"check-dynamic-typing.test",
5754
"check-expressions.test",
5855
"check-functions.test",
5956
"check-generic-subtyping.test",

test-data/unit/check-basic.test

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
[out]
33

44
[case testAssignmentAndVarDef]
5-
a = None # type: A
6-
b = None # type: B
5+
a: A
6+
b: B
77
if int():
88
a = a
99
if int():
@@ -17,23 +17,23 @@ class A:
1717
class B:
1818
def __init__(self): pass
1919

20-
x = None # type: A
20+
x: A
2121
x = A()
2222
if int():
2323
x = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
2424
[case testInheritInitFromObject]
2525
class A(object): pass
2626
class B(object): pass
27-
x = None # type: A
27+
x: A
2828
if int():
2929
x = A()
3030
if int():
3131
x = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
3232
[case testImplicitInheritInitFromObject]
3333
class A: pass
3434
class B: pass
35-
x = None # type: A
36-
o = None # type: object
35+
x: A
36+
o: object
3737
if int():
3838
x = o # E: Incompatible types in assignment (expression has type "object", variable has type "A")
3939
if int():
@@ -59,7 +59,7 @@ x = B() # type: A
5959
y = A() # type: B # E: Incompatible types in assignment (expression has type "A", variable has type "B")
6060
[case testDeclaredVariableInParentheses]
6161

62-
(x) = None # type: int
62+
(x) = 2 # type: int
6363
if int():
6464
x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
6565
if int():
@@ -135,8 +135,8 @@ main:6: error: Missing positional arguments "baz", "bas" in call to "foo"
135135

136136
[case testLocalVariables]
137137
def f() -> None:
138-
x = None # type: A
139-
y = None # type: B
138+
x: A
139+
y: B
140140
if int():
141141
x = x
142142
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,
229229
[case testLocalVariableShadowing]
230230
class A: pass
231231
class B: pass
232-
a = None # type: A
232+
a: A
233233
if int():
234234
a = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
235235
a = A()
236236
def f() -> None:
237-
a = None # type: B
237+
a: B
238238
if int():
239239
a = A() # E: Incompatible types in assignment (expression has type "A", variable has type "B")
240240
a = B()
241241
a = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
242242
a = A()
243243
[case testGlobalDefinedInBlockWithType]
244244
class A: pass
245-
while A:
246-
a = None # type: A
245+
while 1:
246+
a: A
247247
if int():
248248
a = A()
249249
a = object() # E: Incompatible types in assignment (expression has type "object", variable has type "A")

test-data/unit/check-bound.test

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ T = TypeVar('T', bound=A)
3737
class G(Generic[T]):
3838
def __init__(self, x: T) -> None: pass
3939

40-
v = None # type: G[A]
41-
w = None # type: G[B]
42-
x = None # type: G[str] # E: Type argument "str" of "G" must be a subtype of "A"
40+
v: G[A]
41+
w: G[B]
42+
x: G[str] # E: Type argument "str" of "G" must be a subtype of "A"
4343
y = G('a') # E: Value of type variable "T" of "G" cannot be "str"
4444
z = G(A())
4545
z = G(B())
4646

4747

4848
[case testBoundVoid]
49+
# flags: --no-strict-optional
4950
from typing import TypeVar, Generic
5051
T = TypeVar('T', bound=int)
5152
class C(Generic[T]):
@@ -70,10 +71,11 @@ def g(): pass
7071

7172
f(g())
7273
C(g())
73-
z = None # type: C
74+
z: C
7475

7576

7677
[case testBoundHigherOrderWithVoid]
78+
# flags: --no-strict-optional
7779
from typing import TypeVar, Callable
7880
class A: pass
7981
T = TypeVar('T', bound=A)

0 commit comments

Comments
 (0)