From 957307b785d7b55d9234e484a33250179ce1f347 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Thu, 15 Dec 2016 17:53:38 -0800 Subject: [PATCH] Make filter work properly with Optional elements (#775) --- stdlib/2/__builtin__.pyi | 4 ++++ stdlib/3/builtins.pyi | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index b6de92b57..ee7b572d5 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -680,6 +680,10 @@ def divmod(a: int, b: int) -> Tuple[int, int]: ... @overload def divmod(a: float, b: float) -> Tuple[float, float]: ... def exit(code: int = ...) -> None: ... +@overload +def filter(function: None, + iterable: Iterable[Optional[_T]]) -> List[_T]: ... +@overload def filter(function: Callable[[_T], Any], iterable: Iterable[_T]) -> List[_T]: ... def format(o: object, format_spec: str = '') -> str: ... # TODO unicode diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 3847506a8..0f3c12b97 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -696,7 +696,10 @@ def eval(source: str, globals: Dict[str, Any] = None, def exec(object: str, globals: Dict[str, Any] = None, locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source def exit(code: int = None) -> None: ... -def filter(function: Optional[Callable[[_T], Any]], iterable: Iterable[_T]) -> Iterator[_T]: ... +@overload +def filter(function: None, iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... +@overload +def filter(function: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... def format(o: object, format_spec: str = '') -> str: ... def getattr(o: Any, name: str, default: Any = ...) -> Any: ... def globals() -> Dict[str, Any]: ...