@@ -103,10 +103,30 @@ def main(a: object) -> None:
103
103
[builtins fixtures/tuple.pyi]
104
104
105
105
[case testTypeGuardNonzeroFloat]
106
- from typing import Union
107
106
from typing_extensions import TypeGuard
108
107
def is_nonzero(a: object) -> TypeGuard[float]: pass
109
108
def main(a: int):
110
109
if is_nonzero(a):
111
110
reveal_type(a) # N: Revealed type is 'builtins.float'
112
111
[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