Skip to content

Commit 8f66718

Browse files
authored
Enable strict optional for more test files (1) (#15595)
1 parent c13f1d4 commit 8f66718

File tree

5 files changed

+82
-69
lines changed

5 files changed

+82
-69
lines changed

mypy/test/testcheck.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@
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-abstract.test",
55-
"check-async-await.test",
5654
"check-basic.test",
5755
"check-bound.test",
58-
"check-classes.test",
5956
"check-dynamic-typing.test",
60-
"check-enum.test",
6157
"check-expressions.test",
6258
"check-formatting.test",
6359
"check-functions.test",

test-data/unit/check-abstract.test

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
from abc import abstractmethod, ABCMeta
1111

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
1717

1818
def f(): i, j, a, b, c # Prevent redefinition
1919

@@ -44,10 +44,10 @@ class C(I): pass
4444

4545
from abc import abstractmethod, ABCMeta
4646

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
5151

5252
def f(): i, j, a, o # Prevent redefinition
5353

@@ -73,9 +73,9 @@ class A(J): pass
7373
[case testInheritingAbstractClassInSubclass]
7474
from abc import abstractmethod, ABCMeta
7575

76-
i = None # type: I
77-
a = None # type: A
78-
b = None # type: B
76+
i: I
77+
a: A
78+
b: B
7979

8080
if int():
8181
i = a # E: Incompatible types in assignment (expression has type "A", variable has type "I")
@@ -106,8 +106,8 @@ class I(metaclass=ABCMeta):
106106
@abstractmethod
107107
def f(self): pass
108108

109-
o = None # type: object
110-
t = None # type: type
109+
o: object
110+
t: type
111111

112112
o = I
113113
t = I
@@ -122,8 +122,10 @@ class I(metaclass=ABCMeta):
122122
class A(I): pass
123123
class B: pass
124124

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
127129

128130
if int():
129131
a = cast(I, o) # E: Incompatible types in assignment (expression has type "I", variable has type "A")
@@ -220,6 +222,7 @@ f(GoodAlias)
220222
[out]
221223

222224
[case testInstantiationAbstractsInTypeForVariables]
225+
# flags: --no-strict-optional
223226
from typing import Type
224227
from abc import abstractmethod
225228

@@ -399,7 +402,9 @@ class I(metaclass=ABCMeta):
399402
@abstractmethod
400403
def f(self, a: int) -> str: pass
401404

402-
i, a, b = None, None, None # type: (I, int, str)
405+
i: I
406+
a: int
407+
b: str
403408

404409
if int():
405410
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):
419424
def f(self, a: int) -> str: pass
420425
class I(J): pass
421426

422-
i, a, b = None, None, None # type: (I, int, str)
427+
i: I
428+
a: int
429+
b: str
423430

424431
if int():
425432
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):
505512
@abstractmethod
506513
def g(self) -> None: pass
507514
class C(A, B): pass
508-
x = None # type: C
515+
x: C
509516
x.f()
510517
x.g()
511518
x.f(x) # E: Too many arguments for "f" of "A"
@@ -737,6 +744,7 @@ class A(metaclass=ABCMeta):
737744
def x(self, x: int) -> None: pass
738745

739746
[case testReadWriteDeleteAbstractProperty]
747+
# flags: --no-strict-optional
740748
from abc import ABC, abstractmethod
741749
class Abstract(ABC):
742750
@property
@@ -853,6 +861,7 @@ main:8: error: Cannot instantiate abstract class "B" with abstract attribute "x"
853861
main:9: error: "int" has no attribute "y"
854862

855863
[case testSuperWithAbstractProperty]
864+
# flags: --no-strict-optional
856865
from abc import abstractproperty, ABCMeta
857866
class A(metaclass=ABCMeta):
858867
@abstractproperty

test-data/unit/check-async-await.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ async def f() -> None:
291291
[typing fixtures/typing-async.pyi]
292292

293293
[case testAsyncWithErrorBadAenter2]
294-
294+
# flags: --no-strict-optional
295295
class C:
296296
def __aenter__(self) -> None: pass
297297
async def __aexit__(self, x, y, z) -> None: pass
@@ -313,7 +313,7 @@ async def f() -> None:
313313
[typing fixtures/typing-async.pyi]
314314

315315
[case testAsyncWithErrorBadAexit2]
316-
316+
# flags: --no-strict-optional
317317
class C:
318318
async def __aenter__(self) -> int: pass
319319
def __aexit__(self, x, y, z) -> None: pass

0 commit comments

Comments
 (0)