Skip to content

Commit 0d549ad

Browse files
committed
Add more explicit tests
1 parent dc581d7 commit 0d549ad

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

test-data/unit/check-isinstance.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,6 +2661,33 @@ y: Any
26612661
if 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]
26652692
from typing import Union
26662693

test-data/unit/check-typevar-values.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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]

0 commit comments

Comments
 (0)