File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -2661,6 +2661,33 @@ y: Any
26612661if type(y) is int:
26622662 reveal_type(y) # N: Revealed type is "builtins.int"
26632663
2664+ [case testTypeEqualsCheckUsingIsNonOverlapping]
2665+ # flags: --warn-unreachable
2666+ from typing import Union
2667+
2668+ y: str
2669+ if type(y) is int: # E: Subclass of "str" and "int" cannot exist: would have incompatible method signatures
2670+ y # E: Statement is unreachable
2671+ else:
2672+ reveal_type(y) # N: Revealed type is "builtins.str"
2673+ [builtins fixtures/isinstance.pyi]
2674+
2675+ [case testTypeEqualsCheckUsingIsNonOverlappingChild-xfail]
2676+ # flags: --warn-unreachable
2677+ from typing import Union
2678+
2679+ class A: ...
2680+ class B: ...
2681+ class C(A): ...
2682+ x: Union[B, C]
2683+ # C instance cannot be exactly its parent A, we need reversed subtyping relationship
2684+ # here (type(parent) is Child).
2685+ if type(x) is A:
2686+ reveal_type(x) # E: Statement is unreachable
2687+ else:
2688+ reveal_type(x) # N: Revealed type is "Union[__main__.B, __main__.C]"
2689+ [builtins fixtures/isinstance.pyi]
2690+
26642691[case testTypeEqualsNarrowingUnionWithElse]
26652692from typing import Union
26662693
Original file line number Diff line number Diff line change @@ -744,5 +744,4 @@ def fn(w: W) -> W:
744744 elif type(w) is int:
745745 reveal_type(w) # N: Revealed type is "builtins.int"
746746 return w
747-
748747[builtins fixtures/isinstance.pyi]
You can’t perform that action at this time.
0 commit comments