Skip to content

Commit

Permalink
Add TypeIs traversing in in TypeTraverserVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
sloboegen committed Mar 28, 2024
1 parent af82942 commit 2558b00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mypy/typetraverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def visit_callable_type(self, t: CallableType) -> None:
if t.type_guard is not None:
t.type_guard.accept(self)

if t.type_is is not None:
t.type_is.accept(self)

def visit_tuple_type(self, t: TupleType) -> None:
self.traverse_types(t.items)
t.partial_fallback.accept(self)
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-typeis.test
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ def main(a: Tuple[object, ...]):
reveal_type(a) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
[builtins fixtures/tuple.pyi]

[case testTypeIsTypeVarReturn]
from typing import Callable, Optional, TypeVar
from typing_extensions import TypeIs
T = TypeVar('T')
def is_str(x: object) -> TypeIs[str]: pass
def main(x: object, type_check_func: Callable[[object], TypeIs[T]]) -> T:
if not type_check_func(x):
raise Exception()
return x
reveal_type(main("a", is_str)) # N: Revealed type is "builtins.str"
[builtins fixtures/exception.pyi]

[case testTypeIsUnionIn]
from typing import Union
from typing_extensions import TypeIs
Expand Down

0 comments on commit 2558b00

Please sign in to comment.