Issue 35006: itertools.combinations has wrong type when using the typing package (original) (raw)

If I run mypy on the following file called test.py, I get an error:

# test.py
from typing import Iterator, Tuple
import itertools as it

a : Iterator[Tuple[int, ...]]
a = it.product([1,2,3], repeat = 2)

b : Iterator[Tuple[int, ...]]
b = it.combinations([1,2,3], 2)

The line about a goes through without complain. But mypy complains about b by printing the following error message--

test.py:8: error: Incompatible types in assignment (expression has type "Iterable[Tuple[int, ...]]", variable has type "Iterator[Tuple[int, ...]]") test.py:8: note: 'Iterable' is missing following 'Iterator' protocol member: test.py:8: note: next

So basically, it.product is an Iterator but it.combinations is an Iterable (I think it should be an iterator too). I think (without a lot of evidence) that this is a bug in itertools and not in typing.

PS: I apologize if my comment is not formatted according to best practices. This is my first time registering a new issue.