From 39008d51c15906f86b57466fb8001f0031561e61 Mon Sep 17 00:00:00 2001 From: Mark <40182894+mrg29@users.noreply.github.com> Date: Sun, 9 Feb 2020 06:34:41 -0600 Subject: [PATCH] Make `itertools.cycle` a type (#3732) --- stdlib/2/itertools.pyi | 6 +++++- stdlib/3/itertools.pyi | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/stdlib/2/itertools.pyi b/stdlib/2/itertools.pyi index 1d5b4ee84..97e69f802 100644 --- a/stdlib/2/itertools.pyi +++ b/stdlib/2/itertools.pyi @@ -10,7 +10,11 @@ _S = TypeVar('_S') def count(start: int = ..., step: int = ...) -> Iterator[int]: ... # more general types? -def cycle(iterable: Iterable[_T]) -> Iterator[_T]: ... + +class cycle(Iterator[_T], Generic[_T]): + def __init__(self, iterable: Iterable[_T]) -> None: ... + def next(self) -> _T: ... + def __iter__(self) -> Iterator[_T]: ... def repeat(object: _T, times: int = ...) -> Iterator[_T]: ... diff --git a/stdlib/3/itertools.pyi b/stdlib/3/itertools.pyi index 78149e2f4..b5f75fe1c 100644 --- a/stdlib/3/itertools.pyi +++ b/stdlib/3/itertools.pyi @@ -13,7 +13,11 @@ Predicate = Callable[[_T], object] def count(start: _N = ..., step: _N = ...) -> Iterator[_N]: ... # more general types? -def cycle(iterable: Iterable[_T]) -> Iterator[_T]: ... + +class cycle(Iterator[_T], Generic[_T]): + def __init__(self, iterable: Iterable[_T]) -> None: ... + def __next__(self) -> _T: ... + def __iter__(self) -> Iterator[_T]: ... @overload def repeat(object: _T) -> Iterator[_T]: ...