Skip to content

Mypy doesn't recognize objects implementing __iter__ as being Iterable #2598

@rowillia

Description

@rowillia

This might be in the category of issues around supporting protocol methods as a whole.

test_iter.py:

from typing import Iterator

class Foo(object):
    def __iter__(self) -> Iterator[int]:
        yield 1
        yield 2

for x in Foo():
    print(x)
$ mypy test_iter.py
test_iter.py:8: error: Iterable expected

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