diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index c05dfdef2bf7..51d982f35a44 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -866,6 +866,7 @@ main:2: note: Revealed type is "Literal[1]?" main:2: note: Revealed type is "Literal['foo']?" [case testEnumReachabilityChecksBasic] +# flags: --warn-unreachable from enum import Enum from typing import Literal @@ -882,7 +883,7 @@ elif x is Foo.B: elif x is Foo.C: reveal_type(x) # N: Revealed type is "Literal[__main__.Foo.C]" else: - reveal_type(x) # No output here: this branch is unreachable + reveal_type(x) # E: Statement is unreachable reveal_type(x) # N: Revealed type is "Literal[__main__.Foo.A] | Literal[__main__.Foo.B] | Literal[__main__.Foo.C]" if Foo.A is x: @@ -892,7 +893,7 @@ elif Foo.B is x: elif Foo.C is x: reveal_type(x) # N: Revealed type is "Literal[__main__.Foo.C]" else: - reveal_type(x) # No output here: this branch is unreachable + reveal_type(x) # E: Statement is unreachable reveal_type(x) # N: Revealed type is "Literal[__main__.Foo.A] | Literal[__main__.Foo.B] | Literal[__main__.Foo.C]" y: Foo @@ -903,7 +904,7 @@ elif y is Foo.B: elif y is Foo.C: reveal_type(y) # N: Revealed type is "Literal[__main__.Foo.C]" else: - reveal_type(y) # No output here: this branch is unreachable + reveal_type(y) # E: Statement is unreachable reveal_type(y) # N: Revealed type is "__main__.Foo" if Foo.A is y: @@ -913,11 +914,12 @@ elif Foo.B is y: elif Foo.C is y: reveal_type(y) # N: Revealed type is "Literal[__main__.Foo.C]" else: - reveal_type(y) # No output here: this branch is unreachable + reveal_type(y) # E: Statement is unreachable reveal_type(y) # N: Revealed type is "__main__.Foo" [builtins fixtures/bool.pyi] [case testEnumReachabilityChecksWithOrdering] +# flags: --warn-unreachable from enum import Enum from typing import Literal @@ -934,7 +936,7 @@ if x is Foo.A: elif x is Foo.B: reveal_type(x) # N: Revealed type is "Literal[__main__.Foo.B]" else: - reveal_type(x) # No output here: this branch is unreachable + reveal_type(x) # E: Statement is unreachable class Bar(Enum): __order__ = "A B" @@ -949,7 +951,7 @@ if y is Bar.A: elif y is Bar.B: reveal_type(y) # N: Revealed type is "Literal[__main__.Bar.B]" else: - reveal_type(y) # No output here: this branch is unreachable + reveal_type(y) # E: Statement is unreachable x2: Foo if x2 is Foo.A: @@ -957,7 +959,7 @@ if x2 is Foo.A: elif x2 is Foo.B: reveal_type(x2) # N: Revealed type is "Literal[__main__.Foo.B]" else: - reveal_type(x2) # No output here: this branch is unreachable + reveal_type(x2) # E: Statement is unreachable y2: Bar if y2 is Bar.A: @@ -965,10 +967,11 @@ if y2 is Bar.A: elif y2 is Bar.B: reveal_type(y2) # N: Revealed type is "Literal[__main__.Bar.B]" else: - reveal_type(y2) # No output here: this branch is unreachable + reveal_type(y2) # E: Statement is unreachable [builtins fixtures/tuple.pyi] [case testEnumReachabilityChecksIndirect] +# flags: --warn-unreachable from enum import Enum from typing import Final, Literal @@ -1022,18 +1025,19 @@ if y is z: reveal_type(z) # N: Revealed type is "Literal[__main__.Foo.A]?" accepts_foo_a(z) else: - reveal_type(y) # No output: this branch is unreachable - reveal_type(z) # No output: this branch is unreachable + reveal_type(y) # E: Statement is unreachable + reveal_type(z) if z is y: reveal_type(y) # N: Revealed type is "Literal[__main__.Foo.A]" reveal_type(z) # N: Revealed type is "Literal[__main__.Foo.A]?" accepts_foo_a(z) else: - reveal_type(y) # No output: this branch is unreachable - reveal_type(z) # No output: this branch is unreachable + reveal_type(y) # E: Statement is unreachable + reveal_type(z) [builtins fixtures/bool.pyi] [case testEnumReachabilityNarrowingForUnionMessiness] +# flags: --warn-unreachable from enum import Enum from typing import Literal @@ -1062,6 +1066,7 @@ else: [builtins fixtures/bool.pyi] [case testEnumReachabilityWithNone] +# flags: --warn-unreachable from enum import Enum from typing import Optional @@ -1089,6 +1094,7 @@ reveal_type(x) # N: Revealed type is "__main__.Foo | None" [builtins fixtures/enum.pyi] [case testEnumReachabilityWithMultipleEnums] +# flags: --warn-unreachable from enum import Enum from typing import Literal, Union @@ -1123,6 +1129,7 @@ reveal_type(x3) # N: Revealed type is "__main__.Foo | __main__.Bar" [builtins fixtures/bool.pyi] [case testEnumReachabilityPEP484ExampleWithFinal] +# flags: --warn-unreachable from typing import Final, Union from enum import Enum @@ -1146,6 +1153,7 @@ def func(x: Union[int, None, Empty] = _empty) -> int: [builtins fixtures/primitives.pyi] [case testEnumReachabilityPEP484ExampleWithMultipleValues] +# flags: --warn-unreachable from typing import Union from enum import Enum @@ -1168,6 +1176,7 @@ def process(response: Union[str, Reason] = '') -> str: [case testEnumReachabilityPEP484ExampleSingleton] +# flags: --warn-unreachable from typing import Final, Union from enum import Enum @@ -1191,7 +1200,7 @@ def func(x: Union[int, None, Empty] = _empty) -> int: [builtins fixtures/primitives.pyi] [case testEnumReachabilityPEP484ExampleSingletonWithMethod] -# flags: --python-version 3.11 +# flags: --python-version 3.11 --warn-unreachable from typing import Final, Union from enum import Enum, member @@ -1232,6 +1241,7 @@ reveal_type(A().b) # N: Revealed type is "Any" [builtins fixtures/enum.pyi] [case testEnumReachabilityWithChaining] +# flags: --warn-unreachable from enum import Enum class Foo(Enum): diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 542cbb3fd22c..699e83ccbd9f 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -1523,15 +1523,16 @@ else: # N: def f(int, /) -> None [case testConditionalFunctionDefinitionUnreachable] +# flags: --warn-unreachable def bar() -> None: if False: - foo = 1 + foo = 1 # E: Statement is unreachable else: def foo(obj): ... def baz() -> None: if False: - foo: int = 1 + foo: int = 1 # E: Statement is unreachable else: def foo(obj): ... # E: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type "int") [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 447989082088..a51445ef0b5b 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -1729,6 +1729,7 @@ if isinstance(x, Iterable): [typing fixtures/typing-full.pyi] [case testConcreteClassesInProtocolsIsInstance] +# flags: --warn-unreachable from typing import Protocol, runtime_checkable, TypeVar, Generic T = TypeVar('T') @@ -1757,25 +1758,25 @@ c = C() if isinstance(c, P1): reveal_type(c) # N: Revealed type is "__main__.C" else: - reveal_type(c) # Unreachable + reveal_type(c) # E: Statement is unreachable if isinstance(c, P): reveal_type(c) # N: Revealed type is "__main__.C" else: - reveal_type(c) # Unreachable + reveal_type(c) # E: Statement is unreachable c1i: C1[int] if isinstance(c1i, P1): reveal_type(c1i) # N: Revealed type is "__main__.C1[builtins.int]" else: - reveal_type(c1i) # Unreachable + reveal_type(c1i) # E: Statement is unreachable if isinstance(c1i, P): reveal_type(c1i) # N: Revealed type is "__main__." else: reveal_type(c1i) # N: Revealed type is "__main__.C1[builtins.int]" c1s: C1[str] -if isinstance(c1s, P1): - reveal_type(c1s) # Unreachable +if isinstance(c1s, P1): # E: Subclass of "C1[str]" and "P1" cannot exist: would have incompatible method signatures + reveal_type(c1s) # E: Statement is unreachable else: reveal_type(c1s) # N: Revealed type is "__main__.C1[builtins.str]"