Skip to content

Commit

Permalink
Remove unneeded --strict-optional flags from test cases (#15684)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Jul 17, 2023
1 parent 3240da4 commit 3f601c3
Show file tree
Hide file tree
Showing 44 changed files with 58 additions and 248 deletions.
17 changes: 0 additions & 17 deletions test-data/unit/check-abstract.test
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,6 @@ b.y = 1
-- -----------------------------------------------

[case testEmptyBodyProhibitedFunction]
# flags: --strict-optional
from typing import overload, Union

def func1(x: str) -> int: pass # E: Missing return statement
Expand All @@ -1148,7 +1147,6 @@ def func5(x: Union[int, str]) -> Union[int, str]: # E: Missing return statement
"""Some function."""

[case testEmptyBodyProhibitedMethodNonAbstract]
# flags: --strict-optional
from typing import overload, Union

class A:
Expand Down Expand Up @@ -1183,7 +1181,6 @@ class C:
[builtins fixtures/classmethod.pyi]

[case testEmptyBodyProhibitedPropertyNonAbstract]
# flags: --strict-optional
class A:
@property
def x(self) -> int: ... # E: Missing return statement
Expand Down Expand Up @@ -1212,7 +1209,6 @@ class C:
[builtins fixtures/property.pyi]

[case testEmptyBodyNoteABCMeta]
# flags: --strict-optional
from abc import ABC

class A(ABC):
Expand All @@ -1221,7 +1217,6 @@ class A(ABC):
...

[case testEmptyBodyAllowedFunctionStub]
# flags: --strict-optional
import stub
[file stub.pyi]
from typing import overload, Union
Expand All @@ -1232,7 +1227,6 @@ def func3(x: str) -> int:
"""Some function."""

[case testEmptyBodyAllowedMethodNonAbstractStub]
# flags: --strict-optional
import stub
[file stub.pyi]
from typing import overload, Union
Expand All @@ -1254,7 +1248,6 @@ class B:
[builtins fixtures/classmethod.pyi]

[case testEmptyBodyAllowedPropertyNonAbstractStub]
# flags: --strict-optional
import stub
[file stub.pyi]
class A:
Expand Down Expand Up @@ -1285,7 +1278,6 @@ class C:
[builtins fixtures/property.pyi]

[case testEmptyBodyAllowedMethodAbstract]
# flags: --strict-optional
from typing import overload, Union
from abc import abstractmethod

Expand Down Expand Up @@ -1333,7 +1325,6 @@ class C:
[builtins fixtures/classmethod.pyi]

[case testEmptyBodyAllowedPropertyAbstract]
# flags: --strict-optional
from abc import abstractmethod
class A:
@property
Expand Down Expand Up @@ -1372,7 +1363,6 @@ class C:
[builtins fixtures/property.pyi]

[case testEmptyBodyImplicitlyAbstractProtocol]
# flags: --strict-optional
from typing import Protocol, overload, Union

class P1(Protocol):
Expand Down Expand Up @@ -1413,7 +1403,6 @@ C3()
[builtins fixtures/classmethod.pyi]

[case testEmptyBodyImplicitlyAbstractProtocolProperty]
# flags: --strict-optional
from typing import Protocol

class P1(Protocol):
Expand Down Expand Up @@ -1443,7 +1432,6 @@ C2()
[builtins fixtures/property.pyi]

[case testEmptyBodyImplicitlyAbstractProtocolStub]
# flags: --strict-optional
from stub import P1, P2, P3, P4

class B1(P1): ...
Expand Down Expand Up @@ -1479,7 +1467,6 @@ class P4(Protocol):
[builtins fixtures/classmethod.pyi]

[case testEmptyBodyUnsafeAbstractSuper]
# flags: --strict-optional
from stub import StubProto, StubAbstract
from typing import Protocol
from abc import abstractmethod
Expand Down Expand Up @@ -1528,7 +1515,6 @@ class StubAbstract:
def meth(self) -> int: ...

[case testEmptyBodyUnsafeAbstractSuperProperty]
# flags: --strict-optional
from stub import StubProto, StubAbstract
from typing import Protocol
from abc import abstractmethod
Expand Down Expand Up @@ -1586,7 +1572,6 @@ class StubAbstract:
[builtins fixtures/property.pyi]

[case testEmptyBodyUnsafeAbstractSuperOverloads]
# flags: --strict-optional
from stub import StubProto
from typing import Protocol, overload, Union

Expand Down Expand Up @@ -1671,7 +1656,6 @@ class SubAbstract(Abstract):
return super().meth()

[case testEmptyBodyNoSuperWarningOptionalReturn]
# flags: --strict-optional
from typing import Protocol, Optional
from abc import abstractmethod

Expand All @@ -1689,7 +1673,6 @@ class SubAbstract(Abstract):
return super().meth()

[case testEmptyBodyTypeCheckingOnly]
# flags: --strict-optional
from typing import TYPE_CHECKING

class C:
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]
[builtins fixtures/dict.pyi]

[case testDistinctTypes]
# flags: --strict-optional
import b

[file a.py]
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-class-namedtuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ UserDefined(1) # E: Argument 1 to "UserDefined" has incompatible type "int"; ex
[builtins fixtures/list.pyi]

[case testNewNamedTupleWithDefaultsStrictOptional]
# flags: --strict-optional
from typing import List, NamedTuple, Optional

class HasNone(NamedTuple):
Expand Down
36 changes: 14 additions & 22 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@ if int():
b = D2()

[case testConstructorJoinsWithCustomMetaclass]
# flags: --strict-optional
from typing import TypeVar
import abc

Expand Down Expand Up @@ -1629,7 +1628,6 @@ a = A()
reveal_type(a.f) # N: Revealed type is "__main__.D"

[case testAccessingDescriptorFromClass]
# flags: --strict-optional
from d import D, Base
class A(Base):
f = D()
Expand All @@ -1647,7 +1645,6 @@ class D:
[builtins fixtures/bool.pyi]

[case testAccessingDescriptorFromClassWrongBase]
# flags: --strict-optional
from d import D, Base
class A:
f = D()
Expand All @@ -1664,13 +1661,13 @@ class D:
def __get__(self, inst: Base, own: Type[Base]) -> str: pass
[builtins fixtures/bool.pyi]
[out]
main:5: error: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "Type[Base]"
main:5: note: Revealed type is "d.D"
main:6: error: No overload variant of "__get__" of "D" matches argument types "A", "Type[A]"
main:6: note: Possible overload variants:
main:6: note: def __get__(self, inst: None, own: Type[Base]) -> D
main:6: note: def __get__(self, inst: Base, own: Type[Base]) -> str
main:6: note: Revealed type is "Any"
main:4: error: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "Type[Base]"
main:4: note: Revealed type is "d.D"
main:5: error: No overload variant of "__get__" of "D" matches argument types "A", "Type[A]"
main:5: note: Possible overload variants:
main:5: note: def __get__(self, inst: None, own: Type[Base]) -> D
main:5: note: def __get__(self, inst: Base, own: Type[Base]) -> str
main:5: note: Revealed type is "Any"

[case testAccessingGenericNonDataDescriptor]
from typing import TypeVar, Type, Generic, Any
Expand Down Expand Up @@ -1702,7 +1699,6 @@ a.g = ''
a.g = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "str")

[case testAccessingGenericDescriptorFromClass]
# flags: --strict-optional
from d import D
class A:
f = D(10) # type: D[A, int]
Expand All @@ -1724,7 +1720,6 @@ class D(Generic[T, V]):
[builtins fixtures/bool.pyi]

[case testAccessingGenericDescriptorFromInferredClass]
# flags: --strict-optional
from typing import Type
from d import D
class A:
Expand All @@ -1745,11 +1740,10 @@ class D(Generic[T, V]):
def __get__(self, inst: T, own: Type[T]) -> V: pass
[builtins fixtures/bool.pyi]
[out]
main:8: note: Revealed type is "d.D[__main__.A, builtins.int]"
main:9: note: Revealed type is "d.D[__main__.A, builtins.str]"
main:7: note: Revealed type is "d.D[__main__.A, builtins.int]"
main:8: note: Revealed type is "d.D[__main__.A, builtins.str]"

[case testAccessingGenericDescriptorFromClassBadOverload]
# flags: --strict-optional
from d import D
class A:
f = D(10) # type: D[A, int]
Expand All @@ -1766,11 +1760,11 @@ class D(Generic[T, V]):
def __get__(self, inst: T, own: Type[T]) -> V: pass
[builtins fixtures/bool.pyi]
[out]
main:5: error: No overload variant of "__get__" of "D" matches argument types "None", "Type[A]"
main:5: note: Possible overload variants:
main:5: note: def __get__(self, inst: None, own: None) -> D[A, int]
main:5: note: def __get__(self, inst: A, own: Type[A]) -> int
main:5: note: Revealed type is "Any"
main:4: error: No overload variant of "__get__" of "D" matches argument types "None", "Type[A]"
main:4: note: Possible overload variants:
main:4: note: def __get__(self, inst: None, own: None) -> D[A, int]
main:4: note: def __get__(self, inst: A, own: Type[A]) -> int
main:4: note: Revealed type is "Any"

[case testAccessingNonDataDescriptorSubclass]
from typing import Any
Expand Down Expand Up @@ -6484,7 +6478,6 @@ def deco(f: Callable[..., T]) -> Callable[..., Tuple[T, int]]: ...
[out]

[case testOptionalDescriptorsBinder]
# flags: --strict-optional
from typing import Type, TypeVar, Optional
T = TypeVar('T')

Expand Down Expand Up @@ -6698,7 +6691,6 @@ class C(Generic[T]):
[builtins fixtures/isinstancelist.pyi]

[case testIsInstanceTypeSubclass]
# flags: --strict-optional
from typing import Type, Optional
class Base: ...
class One(Base):
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-columns.test
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ A().f(1, 1) # E:10: Argument 2 to "f" of "A" has incompatible type "int"; expect
(A().f(1, 'hello', 'hi')) # E:2: Too many arguments for "f" of "A"

[case testColumnsInvalidArgumentType]
# flags: --strict-optional
def f(x: int, y: str) -> None: ...
def g(*x: int) -> None: pass
def h(**x: int) -> None: pass
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-custom-plugin.test
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ else:
plugins=<ROOT>/test-data/unit/plugins/union_method.py

[case testGetMethodHooksOnUnionsStrictOptional]
# flags: --config-file tmp/mypy.ini --strict-optional
# flags: --config-file tmp/mypy.ini
from typing import Union

class Foo:
Expand Down
8 changes: 2 additions & 6 deletions test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,6 @@ class Foo:

[case testNoComplainFieldNoneStrict]
# flags: --python-version 3.7
# flags: --strict-optional
from dataclasses import dataclass, field
from typing import Optional

Expand Down Expand Up @@ -1264,7 +1263,7 @@ class Deferred: pass
[builtins fixtures/dataclasses.pyi]

[case testDeferredDataclassInitSignatureSubclass]
# flags: --strict-optional --python-version 3.7
# flags: --python-version 3.7
from dataclasses import dataclass
from typing import Optional

Expand Down Expand Up @@ -1745,7 +1744,7 @@ reveal_type(Child2[int, A]([A()], [1]).b) # N: Revealed type is "builtins.list[
[builtins fixtures/dataclasses.pyi]

[case testDataclassInheritOptionalType]
# flags: --python-version 3.7 --strict-optional
# flags: --python-version 3.7
from dataclasses import dataclass
from typing import Any, Callable, Generic, TypeVar, List, Optional

Expand Down Expand Up @@ -1979,7 +1978,6 @@ B = List[C]
[builtins fixtures/dataclasses.pyi]

[case testDataclassSelfType]
# flags: --strict-optional
from dataclasses import dataclass
from typing import Self, TypeVar, Generic, Optional

Expand Down Expand Up @@ -2104,7 +2102,6 @@ a2 = replace(a, q='42') # E: Argument "q" to "replace" of "A" has incompatible
reveal_type(a2) # N: Revealed type is "__main__.A"

[case testReplaceUnion]
# flags: --strict-optional
from typing import Generic, Union, TypeVar
from dataclasses import dataclass, replace, InitVar

Expand Down Expand Up @@ -2136,7 +2133,6 @@ _ = replace(a_or_b, y=42, init_var=42) # E: Argument "y" to "replace" of "Union
[builtins fixtures/dataclasses.pyi]

[case testReplaceUnionOfTypeVar]
# flags: --strict-optional
from typing import Generic, Union, TypeVar
from dataclasses import dataclass, replace

Expand Down
4 changes: 0 additions & 4 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,6 @@ else:
[builtins fixtures/bool.pyi]

[case testEnumReachabilityWithNone]
# flags: --strict-optional
from enum import Enum
from typing import Optional

Expand Down Expand Up @@ -1016,7 +1015,6 @@ reveal_type(x3) # N: Revealed type is "Union[__main__.Foo, __main__.Bar]"
[builtins fixtures/bool.pyi]

[case testEnumReachabilityPEP484ExampleWithFinal]
# flags: --strict-optional
from typing import Union
from typing_extensions import Final
from enum import Enum
Expand Down Expand Up @@ -1063,7 +1061,6 @@ def process(response: Union[str, Reason] = '') -> str:


[case testEnumReachabilityPEP484ExampleSingleton]
# flags: --strict-optional
from typing import Union
from typing_extensions import Final
from enum import Enum
Expand All @@ -1088,7 +1085,6 @@ def func(x: Union[int, None, Empty] = _empty) -> int:
[builtins fixtures/primitives.pyi]

[case testEnumReachabilityPEP484ExampleSingletonWithMethod]
# flags: --strict-optional
from typing import Union
from typing_extensions import Final
from enum import Enum
Expand Down
Loading

0 comments on commit 3f601c3

Please sign in to comment.