From 86fc066a696e0f773903a3c203b09e39372dece3 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sun, 10 Oct 2021 01:08:31 +0300 Subject: [PATCH 1/2] Adds `TypeGuard` to `filter` Refs https://github.com/python/typeshed/issues/5661 --- stdlib/builtins.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 75da5c830059..d91d448c8e8d 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -56,6 +56,7 @@ from typing import ( Tuple, Type, TypeVar, + TypeGuard, Union, ValuesView, overload, @@ -1035,6 +1036,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: ... From 90be62211c59d7c1bb61ae15e8bf8f65775cd9e6 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sun, 10 Oct 2021 01:10:14 +0300 Subject: [PATCH 2/2] Update builtins.pyi --- stdlib/builtins.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index d91d448c8e8d..795ed68f4fb0 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -56,12 +56,11 @@ from typing import ( Tuple, Type, TypeVar, - TypeGuard, Union, ValuesView, overload, ) -from typing_extensions import Literal, SupportsIndex, final +from typing_extensions import Literal, SupportsIndex, TypeGuard, final if sys.version_info >= (3, 9): from types import GenericAlias