Skip to content

Commit ac89577

Browse files
authored
Add regression test for isinstance narrowing (#18272)
Regression test for #11839 resolved with #18138.
1 parent ec4ccb0 commit ac89577

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test-data/unit/check-isinstance.test

+15
Original file line numberDiff line numberDiff line change
@@ -2917,3 +2917,18 @@ if hasattr(mod, "y"):
29172917
[file mod.py]
29182918
def __getattr__(attr: str) -> str: ...
29192919
[builtins fixtures/module.pyi]
2920+
2921+
[case testTypeIsntLostAfterNarrowing]
2922+
from typing import Any
2923+
2924+
var: Any
2925+
reveal_type(var) # N: Revealed type is "Any"
2926+
assert isinstance(var, (bool, str))
2927+
reveal_type(var) # N: Revealed type is "Union[builtins.bool, builtins.str]"
2928+
2929+
if isinstance(var, bool):
2930+
reveal_type(var) # N: Revealed type is "builtins.bool"
2931+
2932+
# Type of var shouldn't fall back to Any
2933+
reveal_type(var) # N: Revealed type is "Union[builtins.bool, builtins.str]"
2934+
[builtins fixtures/isinstance.pyi]

0 commit comments

Comments
 (0)