From 8d8a34cb835884d29e90b0de248ef4c702544573 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Tue, 9 May 2017 17:50:11 -0700 Subject: [PATCH] Patch from @sfreilich: make itertools.ifilter predicate parameter Optional (#1257) From Samuel Freilich: In Python 2, the predicate parameter in itertools.ifilter and itertools.ifilterfalse can be None, indicating that true or false values should be retained (functionally equivalent to passing "bool" as the predicate). In Python 3, filter and itertools.filterfalse have the same behavior. --- stdlib/2/itertools.pyi | 4 ++-- stdlib/3/builtins.pyi | 3 ++- stdlib/3/itertools.pyi | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/stdlib/2/itertools.pyi b/stdlib/2/itertools.pyi index 644d9f1b1..4d9edbc32 100644 --- a/stdlib/2/itertools.pyi +++ b/stdlib/2/itertools.pyi @@ -26,9 +26,9 @@ class chain(Iterator[_T], Generic[_T]): def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ... def dropwhile(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... -def ifilter(predicate: Callable[[_T], Any], +def ifilter(predicate: Optional[Callable[[_T], Any]], iterable: Iterable[_T]) -> Iterator[_T]: ... -def ifilterfalse(predicate: Callable[[_T], Any], +def ifilterfalse(predicate: Optional[Callable[[_T], Any]], iterable: Iterable[_T]) -> Iterator[_T]: ... @overload diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index c283abe1d..f2a3b1b92 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -773,7 +773,8 @@ def exec(object: str, globals: Dict[str, Any] = None, locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source def exit(code: Any = ...) -> NoReturn: ... @overload -def filter(function: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... +def filter(function: Optional[Callable[[_T], Any]], + iterable: Iterable[_T]) -> Iterator[_T]: ... @overload def filter(function: None, iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... def format(o: object, format_spec: str = '') -> str: ... diff --git a/stdlib/3/itertools.pyi b/stdlib/3/itertools.pyi index 774d68fb3..3e4379a03 100644 --- a/stdlib/3/itertools.pyi +++ b/stdlib/3/itertools.pyi @@ -29,7 +29,7 @@ class chain(Iterator[_T], Generic[_T]): def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ... def dropwhile(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... -def filterfalse(predicate: Callable[[_T], Any], +def filterfalse(predicate: Optional[Callable[[_T], Any]], iterable: Iterable[_T]) -> Iterator[_T]: ... @overload