Skip to content

Commit eed73f7

Browse files
committed
Add regression tests
1 parent 6e8c42f commit eed73f7

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

test-data/unit/check-isinstance.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,23 @@ if hasattr(mod, "y"):
28852885
def __getattr__(attr: str) -> str: ...
28862886
[builtins fixtures/module.pyi]
28872887

2888+
[case testMultipleHasAttr]
2889+
# flags: --warn-unreachable
2890+
from __future__ import annotations
2891+
from typing import Any
2892+
2893+
def len(obj: object) -> Any: ...
2894+
2895+
def f(x: type | str):
2896+
if (
2897+
hasattr(x, "__origin__")
2898+
and x.__origin__ is list
2899+
and hasattr(x, "__args__")
2900+
and len(x.__args__) == 1
2901+
):
2902+
reveal_type(x.__args__[0]) # N: Revealed type is "Any"
2903+
[builtins fixtures/module.pyi]
2904+
28882905
[case testTypeIsntLostAfterNarrowing]
28892906
from typing import Any
28902907

test-data/unit/check-narrowing.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,3 +3181,21 @@ def main(y: Any):
31813181
reveal_type(y) # N: Revealed type is "builtins.int"
31823182
else:
31833183
reveal_type(y) # N: Revealed type is "Any"
3184+
3185+
[case testNarrowingAnyNegativeIntersection]
3186+
from __future__ import annotations
3187+
from typing import Any
3188+
3189+
class array: ...
3190+
3191+
def get_result() -> Any: ...
3192+
3193+
def foo(x: str | array) -> str:
3194+
result = get_result()
3195+
if isinstance(result, array):
3196+
return "asdf"
3197+
if result is x:
3198+
reveal_type(result) # N: Revealed type is "Any"
3199+
return result
3200+
raise
3201+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)