mypy icon indicating copy to clipboard operation
mypy copied to clipboard

`has no attribute "__aiter__"; maybe "__enter__"? (not async iterable)` when async iterating

Open sliedes opened this issue 1 year ago • 0 comments

Bug Report

On mypy 1.9.0, this code suggests, somewhat nonsensically, __enter__ because __aiter__ does not exist despite the reference to __aiter__ being entirely implicit in the async for loop:

from typing import Self

class Foo:
    def __enter__(self) -> Self:
        return self

async def f() -> None:
    async for x in Foo():
        print(x)

On playground: https://mypy-play.net/?mypy=latest&python=3.12&gist=3971471bd809ed97a72a1423a56f5318

Expected Behavior

Since the user did not type __aiter__, it is unlikely that it would be a typo for __enter__; therefore, probably the most helpful course would be to not give that suggestion.

sliedes avatar Apr 15 '24 12:04 sliedes