Skip to content

Not behaving correctly in zipped loops #7004

Closed
@guillemglez

Description

@guillemglez

This code runs just fine:

for letter, integer_tuple in zip(("a", "b"), ((1, 2), (3, 4, 5))):
    for integer in integer_tuple:
        print(letter, integer)

And output is as expected:

a 1
a 2
b 3
b 4
b 5

Although mypy complains about integer_tuple not being an iterable:

fk.py:2: error: "object" has no attribute "__iter__"; maybe "__str__" or "__dir__"? (not iterable)

Note that this only happens if the second interable in zip contains two iterables with different lengths, but not if they are both the same, i.e. ((1, 2), (3, 4)) does not raise any error from mypy .

Using Python 3.6.8 and mypy 0.701

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions