From 8ecf3ff0b61356161e1e0c930acc44257cb78ef1 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Mon, 3 May 2021 16:34:03 -0700 Subject: [PATCH] Make the `start` argument to itertools.count optional. (#5332) start should be optional: https://docs.python.org/3.8/library/itertools.html#itertools.count Directly changing the second overload to mark start as optional generated a mypy error about overlapping overloads, but adding a third overload seems to work. I also noticed that `_NStep` was defined as a TypeVar when I think it makes more sense for it to be a Union, so I went ahead and changed that as well. --- stdlib/itertools.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/itertools.pyi b/stdlib/itertools.pyi index 3a77edafe..7fe08ca80 100644 --- a/stdlib/itertools.pyi +++ b/stdlib/itertools.pyi @@ -13,6 +13,7 @@ from typing import ( Tuple, Type, TypeVar, + Union, overload, ) from typing_extensions import Literal, SupportsIndex @@ -20,7 +21,7 @@ from typing_extensions import Literal, SupportsIndex _T = TypeVar("_T") _S = TypeVar("_S") _N = TypeVar("_N", int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex) -_NStep = TypeVar("_NStep", int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex) +_Step = Union[int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex] Predicate = Callable[[_T], object] @@ -30,7 +31,9 @@ class count(Iterator[_N], Generic[_N]): @overload def __new__(cls) -> count[int]: ... @overload - def __new__(cls, start: _N, step: _NStep = ...) -> count[_N]: ... + def __new__(cls, start: _N, step: _Step = ...) -> count[_N]: ... + @overload + def __new__(cls, *, step: _N) -> count[_N]: ... def __next__(self) -> _N: ... def __iter__(self) -> Iterator[_N]: ...