Skip to content

Commit 102ac11

Browse files
committed
Add a test about narrowing behavior
1 parent dc8ed71 commit 102ac11

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

test-data/unit/check-unreachable-code.test

+9
Original file line numberDiff line numberDiff line change
@@ -1564,3 +1564,12 @@ if isinstance(x, int):
15641564
def foo(var: str) -> str:
15651565
return "aa" if isinstance(var, str) else 0 # E: If condition is always true
15661566
[builtins fixtures/isinstancelist.pyi]
1567+
1568+
[case testMypyDoesntNarrowBasedOnLies]
1569+
x: int
1570+
if isinstance(x, int):
1571+
assert False
1572+
1573+
reveal_type(x) # N: Revealed type is "builtins.int"
1574+
# mypy should not narrow this ^
1575+
[builtins fixtures/isinstancelist.pyi]

0 commit comments

Comments
 (0)