[New-bugs-announce] [issue35006] itertools.combinations has wrong type when using the typing package

Vaibhav Karve report at bugs.python.org
Tue Oct 16 20:38:14 EDT 2018


New submission from Vaibhav Karve <vaibhavskarve at gmail.com>:

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.

----------
components: Demos and Tools
messages: 327849
nosy: vaibhavkarve
priority: normal
severity: normal
status: open
title: itertools.combinations has wrong type when using the typing package
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35006>
_______________________________________


More information about the New-bugs-announce mailing list