Skip to content

itertools.product with no arguments support #2561

@lycantropos

Description

@lycantropos

It is documented that itertools.product call with no arguments works fine and it is:

test.py

from itertools import product

print(next(product()))  # ()

tested on Python 3.3+ on Linux and on Python 3.0+ on Windows, but running mypy raises error

> mypy test.py
test.py:3: error: All overload variants of "product" require at least one argument
test.py:3: note: Possible overload variants:
test.py:3: note:     def [_T1] product(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]
test.py:3: note:     def [_T1, _T2] product(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]
test.py:3: note:     <6 more similar overloads not shown, out of 8 total overloads>

it happens because there is no support for this kind of call in typeshed, can be fixed by specifying that repeat parameter (added in this PR) has default argument like

@overload
def product(*iterables: Iterable[Any], repeat: int = ...) -> Iterator[Tuple[Any, ...]]: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions