@@ -1127,8 +1127,8 @@ S = Callable[[B], "T"]
11271127
11281128def f(x: S, y: T):
11291129 if x == y: # E: Unsupported left operand type for == ("Callable[[B], T]")
1130- reveal_type(x) # N: Revealed type is "def (__main__.B) -> def (__main__.A) -> ..."
1131- reveal_type(y) # N: Revealed type is "def (__main__.A) -> def (__main__.B) -> ..."
1130+ reveal_type(x) # E: Statement is unreachable
1131+ reveal_type(y)
11321132 else:
11331133 reveal_type(x) # N: Revealed type is "def (__main__.B) -> def (__main__.A) -> ..."
11341134 reveal_type(y) # N: Revealed type is "def (__main__.A) -> def (__main__.B) -> ..."
@@ -2808,7 +2808,7 @@ while True:
28082808 break
28092809 x = str()
28102810 if x == int(): # E: Non-overlapping equality check (left operand type: "str", right operand type: "int")
2811- break
2811+ break # E: Statement is unreachable
28122812[builtins fixtures/primitives.pyi]
28132813
28142814[case testAvoidFalseNonOverlappingEqualityCheckInLoop2]
@@ -2821,7 +2821,7 @@ class C: ...
28212821x = A()
28222822while True:
28232823 if x == C(): # E: Non-overlapping equality check (left operand type: "A | B", right operand type: "C")
2824- break
2824+ break # E: Statement is unreachable
28252825 x = B()
28262826[builtins fixtures/primitives.pyi]
28272827
@@ -3213,7 +3213,7 @@ def narrow_tuple(x: Literal['c'], overlap: list[Literal['b', 'c']], no_overlap:
32133213 reveal_type(x) # N: Revealed type is "Literal['c']"
32143214
32153215 if x in no_overlap:
3216- reveal_type(x) # N: Revealed type is "Literal['c']"
3216+ reveal_type(x) # E: Statement is unreachable
32173217 else:
32183218 reveal_type(x) # N: Revealed type is "Literal['c']"
32193219[builtins fixtures/tuple.pyi]
@@ -3255,8 +3255,8 @@ def f2(x: Any) -> None:
32553255
32563256def bad_compare_has_key(has_key: bool, key: str, s: tuple[str, ...]) -> None:
32573257 if has_key == key in s: # E: Non-overlapping equality check (left operand type: "bool", right operand type: "str")
3258- reveal_type(has_key) # N: Revealed type is "builtins.bool"
3259- reveal_type(key) # N: Revealed type is "builtins.str"
3258+ reveal_type(has_key) # E: Statement is unreachable
3259+ reveal_type(key)
32603260
32613261def bad_but_should_pass(has_key: bool, key: bool, s: tuple[bool, ...]) -> None:
32623262 if has_key == key in s:
@@ -3623,6 +3623,7 @@ def bar(y: Any):
36233623 reveal_type(y) # N: Revealed type is "Any"
36243624[builtins fixtures/dict-full.pyi]
36253625
3626+
36263627[case testNarrowTypeVarType]
36273628# flags: --strict-equality --warn-unreachable
36283629from typing import TypeVar
@@ -3653,14 +3654,14 @@ TargetType = TypeVar("TargetType", int, float, str)
36533654# TODO: this behaviour is incorrect, it will be fixed by improving reachability
36543655def convert_type(target_type: Type[TargetType]) -> TargetType:
36553656 if target_type == str:
3656- return str() # E: Incompatible return value type (got "str", expected "int") \
3657- # E: Incompatible return value type (got "str", expected "float")
3657+ return str()
36583658 if target_type == int:
3659- return int() # E: Incompatible return value type (got "int", expected "str")
3659+ return int()
36603660 if target_type == float:
3661- return float() # E: Incompatible return value type (got "float", expected "int") \
3662- # E: Incompatible return value type (got "float", expected "str")
3661+ return float() # E: Incompatible return value type (got "float", expected "int")
36633662 raise
3663+
3664+
36643665[builtins fixtures/primitives.pyi]
36653666
36663667
@@ -3841,16 +3842,16 @@ class A2(A): ...
38413842
38423843def check_a(base: A, a1: A1, a2: A2):
38433844 if a1 == a2: # E: Non-overlapping equality check (left operand type: "A1", right operand type: "A2")
3844- reveal_type(a1) # N: Revealed type is "__main__.A1"
3845- reveal_type(a2) # N: Revealed type is "__main__.A2"
3845+ reveal_type(a1) # E: Statement is unreachable
3846+ reveal_type(a2)
38463847
38473848 if a1 == base:
38483849 # We do narrow base
38493850 reveal_type(a1) # N: Revealed type is "__main__.A1"
38503851 reveal_type(base) # N: Revealed type is "__main__.A1"
38513852 if a2 == base: # E: Non-overlapping equality check (left operand type: "A2", right operand type: "A1")
3852- reveal_type(a2) # N: Revealed type is "__main__.A2"
3853- reveal_type(base) # N: Revealed type is "__main__.A1"
3853+ reveal_type(a2) # E: Statement is unreachable
3854+ reveal_type(base)
38543855[builtins fixtures/primitives.pyi]
38553856
38563857
0 commit comments