@@ -370,3 +370,47 @@ if guard(a):
370370 reveal_type(a) # N: Revealed type is "__main__.A"
371371reveal_type(a) # N: Revealed type is "__main__.A"
372372[builtins fixtures/tuple.pyi]
373+
374+ [case testTypeGuardNestedRestrictionAny]
375+ from typing_extensions import TypeGuard
376+ from typing import Any
377+
378+ class A: ...
379+ def f(x: object) -> TypeGuard[A]: ...
380+ def g(x: object) -> None: ...
381+
382+ def test(x: Any) -> None:
383+ if not(f(x) or x):
384+ return
385+ g(reveal_type(x)) # N: Revealed type is "Union[__main__.A, Any]"
386+ [builtins fixtures/tuple.pyi]
387+
388+ [case testTypeGuardNestedRestrictionUnionOther]
389+ from typing_extensions import TypeGuard
390+ from typing import Any
391+
392+ class A: ...
393+ class B: ...
394+ def f(x: object) -> TypeGuard[A]: ...
395+ def f2(x: object) -> TypeGuard[B]: ...
396+ def g(x: object) -> None: ...
397+
398+ def test(x: object) -> None:
399+ if not(f(x) or f2(x)):
400+ return
401+ g(reveal_type(x)) # N: Revealed type is "Union[__main__.A, __main__.B]"
402+ [builtins fixtures/tuple.pyi]
403+
404+ [case testTypeGuardNestedRestrictionUnionIsInstance]
405+ from typing_extensions import TypeGuard
406+ from typing import Any, List
407+
408+ class A: ...
409+ def f(x: List[object]) -> TypeGuard[List[str]]: ...
410+ def g(x: object) -> None: ...
411+
412+ def test(x: List[object]) -> None:
413+ if not(f(x) or isinstance(x, A)):
414+ return
415+ g(reveal_type(x)) # N: Revealed type is "Union[builtins.list[builtins.str], __main__.<subclass of "list" and "A">]"
416+ [builtins fixtures/tuple.pyi]
0 commit comments