mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
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 <Alex.Waygood@Gmail.com>
This commit is contained in:
@@ -1065,6 +1065,8 @@ class filter(Iterator[_T], Generic[_T]):
|
||||
@overload
|
||||
def __init__(self, __function: None, __iterable: Iterable[_T | None]) -> None: ...
|
||||
@overload
|
||||
def __init__(self, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> None: ...
|
||||
@overload
|
||||
def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ...
|
||||
def __iter__(self) -> Iterator[_T]: ...
|
||||
def __next__(self) -> _T: ...
|
||||
|
||||
Reference in New Issue
Block a user