Skip to content

Enable strict optional for more test files (1) #15595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,9 @@

# TODO: Enable strict optional in test cases by default. Remove files here, once test cases are updated
no_strict_optional_files = {
"check-abstract.test",
"check-async-await.test",
"check-basic.test",
"check-bound.test",
"check-classes.test",
"check-dynamic-typing.test",
"check-enum.test",
"check-expressions.test",
"check-formatting.test",
"check-functions.test",
Expand Down
47 changes: 28 additions & 19 deletions test-data/unit/check-abstract.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

from abc import abstractmethod, ABCMeta

i = None # type: I
j = None # type: J
a = None # type: A
b = None # type: B
c = None # type: C
i: I
j: J
a: A
b: B
c: C

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

Expand Down Expand Up @@ -44,10 +44,10 @@ class C(I): pass

from abc import abstractmethod, ABCMeta

i = None # type: I
j = None # type: J
a = None # type: A
o = None # type: object
i: I
j: J
a: A
o: object

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

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

i = None # type: I
a = None # type: A
b = None # type: B
i: I
a: A
b: B

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

o = None # type: object
t = None # type: type
o: object
t: type

o = I
t = I
Expand All @@ -122,8 +122,10 @@ class I(metaclass=ABCMeta):
class A(I): pass
class B: pass

i, a, b = None, None, None # type: (I, A, B)
o = None # type: object
i: I
a: A
b: B
o: object

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

[case testInstantiationAbstractsInTypeForVariables]
# flags: --no-strict-optional
from typing import Type
from abc import abstractmethod

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

i, a, b = None, None, None # type: (I, int, str)
i: I
a: int
b: str

if int():
a = i.f(a) # E: Incompatible types in assignment (expression has type "str", variable has type "int")
Expand All @@ -419,7 +424,9 @@ class J(metaclass=ABCMeta):
def f(self, a: int) -> str: pass
class I(J): pass

i, a, b = None, None, None # type: (I, int, str)
i: I
a: int
b: str

if int():
a = i.f(1) # E: Incompatible types in assignment (expression has type "str", variable has type "int")
Expand Down Expand Up @@ -505,7 +512,7 @@ class B(metaclass=ABCMeta):
@abstractmethod
def g(self) -> None: pass
class C(A, B): pass
x = None # type: C
x: C
x.f()
x.g()
x.f(x) # E: Too many arguments for "f" of "A"
Expand Down Expand Up @@ -737,6 +744,7 @@ class A(metaclass=ABCMeta):
def x(self, x: int) -> None: pass

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

[case testSuperWithAbstractProperty]
# flags: --no-strict-optional
from abc import abstractproperty, ABCMeta
class A(metaclass=ABCMeta):
@abstractproperty
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async def f() -> None:
[typing fixtures/typing-async.pyi]

[case testAsyncWithErrorBadAenter2]

# flags: --no-strict-optional
class C:
def __aenter__(self) -> None: pass
async def __aexit__(self, x, y, z) -> None: pass
Expand All @@ -313,7 +313,7 @@ async def f() -> None:
[typing fixtures/typing-async.pyi]

[case testAsyncWithErrorBadAexit2]

# flags: --no-strict-optional
class C:
async def __aenter__(self) -> int: pass
def __aexit__(self, x, y, z) -> None: pass
Expand Down
Loading