Skip to content

Commit 0d2eb06

Browse files
committed
Add two new tests
- walrus - higher-order functions
1 parent cf067d1 commit 0d2eb06

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test-data/unit/check-typeguard.test

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,30 @@ def main(a: object) -> None:
103103
[builtins fixtures/tuple.pyi]
104104

105105
[case testTypeGuardNonzeroFloat]
106-
from typing import Union
107106
from typing_extensions import TypeGuard
108107
def is_nonzero(a: object) -> TypeGuard[float]: pass
109108
def main(a: int):
110109
if is_nonzero(a):
111110
reveal_type(a) # N: Revealed type is 'builtins.float'
112111
[builtins fixtures/tuple.pyi]
112+
113+
[case testTypeGuardHigherOrder]
114+
from typing import Callable, TypeVar, Iterable, List
115+
from typing_extensions import TypeGuard
116+
T = TypeVar('T')
117+
R = TypeVar('R')
118+
def filter(f: Callable[[T], TypeGuard[R]], it: Iterable[T]) -> Iterable[R]: pass
119+
def is_float(a: object) -> TypeGuard[float]: pass
120+
a: List[object] = ["a", 0, 0.0]
121+
# TODO: Make this pass
122+
##reveal_type(filter(is_float, a)) ## N: Revealed type is 'typing.Iterable[float]'
123+
[builtins fixtures/tuple.pyi]
124+
125+
[case testTypeGuardWalrus]
126+
from typing_extensions import TypeGuard
127+
def is_float(a: object) -> TypeGuard[float]: pass
128+
def main(a: object) -> None:
129+
if is_float(x := a):
130+
reveal_type(x) # N: Revealed type is 'builtins.float'
131+
reveal_type(a) # N: Revealed type is 'builtins.object'
132+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)