Skip to content

Commit be99a2a

Browse files
TadaboodyJelleZijlstra
authored andcommitted
Use a more accurate type for predicates in itertools (#2732)
The only constraint on the return value of a predicate is to be "boolable". Because `bool` recives an object in the constructor https://github.com/python/typeshed/blob/master/stdlib/2and3/builtins.pyi#L803 this is a more accurate description of a predicate.
1 parent 0854df3 commit be99a2a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

stdlib/3/itertools.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from typing import (Iterator, TypeVar, Iterable, overload, Any, Callable, Tuple,
88
_T = TypeVar('_T')
99
_S = TypeVar('_S')
1010
_N = TypeVar('_N', int, float)
11+
Predicate = Callable[[_T], object]
1112

1213
def count(start: _N = ...,
1314
step: _N = ...) -> Iterator[_N]: ... # more general types?
@@ -28,9 +29,9 @@ class chain(Iterator[_T], Generic[_T]):
2829
def from_iterable(iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ...
2930

3031
def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ...
31-
def dropwhile(predicate: Callable[[_T], Any],
32+
def dropwhile(predicate: Predicate[_T],
3233
iterable: Iterable[_T]) -> Iterator[_T]: ...
33-
def filterfalse(predicate: Optional[Callable[[_T], Any]],
34+
def filterfalse(predicate: Optional[Predicate[_T]],
3435
iterable: Iterable[_T]) -> Iterator[_T]: ...
3536

3637
@overload
@@ -46,7 +47,7 @@ def islice(iterable: Iterable[_T], start: Optional[int], stop: Optional[int],
4647
step: Optional[int] = ...) -> Iterator[_T]: ...
4748

4849
def starmap(func: Callable[..., _S], iterable: Iterable[Iterable[Any]]) -> Iterator[_S]: ...
49-
def takewhile(predicate: Callable[[_T], Any],
50+
def takewhile(predicate: Predicate[_T],
5051
iterable: Iterable[_T]) -> Iterator[_T]: ...
5152
def tee(iterable: Iterable[_T], n: int = ...) -> Tuple[Iterator[_T], ...]: ...
5253
def zip_longest(*p: Iterable[Any],

0 commit comments

Comments
 (0)