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.
This commit is contained in:
Rebecca Chen
2021-05-03 16:34:03 -07:00
committed by GitHub
parent 38dfb57adf
commit 8ecf3ff0b6

View File

@@ -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]: ...