Skip to content

Commit 7c4ca27

Browse files
Jasha10AlexWaygood
andauthored
builtins.filter compat with typing.TypeGuard (#6726)
This change enables the following use-case: ```python def is_not_none(x: Optional[int]) -> TypeGuard[int]: return x is not None list_optional: list[Optional[int]] = [0, None, 1, None, 2] generate_ints: Iterable[int] = filter(is_not_none, list_optional) ``` Co-authored-by: Alex Waygood <[email protected]>
1 parent 2bf7458 commit 7c4ca27

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

stdlib/builtins.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ class filter(Iterator[_T], Generic[_T]):
10651065
@overload
10661066
def __init__(self, __function: None, __iterable: Iterable[_T | None]) -> None: ...
10671067
@overload
1068+
def __init__(self, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> None: ...
1069+
@overload
10681070
def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ...
10691071
def __iter__(self) -> Iterator[_T]: ...
10701072
def __next__(self) -> _T: ...

0 commit comments

Comments
 (0)