Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.4] Regression with AsyncGenerator #15489

Closed
Dreamsorcerer opened this issue Jun 21, 2023 · 6 comments · Fixed by #15491
Closed

[1.4] Regression with AsyncGenerator #15489

Dreamsorcerer opened this issue Jun 21, 2023 · 6 comments · Fixed by #15491
Labels
bug mypy got something wrong topic-async async, await, asyncio

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Jun 21, 2023

Bug Report

I can't seem to find a minimal reproducer, but whenever using watchfiles.awatch(), mypy produces the error:
error: "Coroutine[Any, Any, AsyncGenerator[set[tuple[Change, str]], None]]" has no attribute "__aiter__" (not async iterable) [attr-defined]

As can be seen in the aiohttp-devtools repo:
https://github.com/aio-libs/aiohttp-devtools/actions/runs/5328161994/jobs/9652470528?pr=572

To Reproduce

from watchfiles import awatch

async def main() -> None:
    async for i in awatch("/foo"):
        print(i)

Expected Behavior

No error, as in mypy<1.4.
Not sure what exactly triggers the error, as writing another async iterator function myself does not trigger it.

@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Jun 21, 2023
@Dreamsorcerer
Copy link
Contributor Author

Source code is just annotated with AsyncGenerator:
https://github.com/samuelcolvin/watchfiles/blob/main/watchfiles/main.py#L137

@AlexWaygood AlexWaygood added the topic-async async, await, asyncio label Jun 21, 2023
@hauntsaninja
Copy link
Collaborator

Hmmm I wonder if related to #14150

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jun 21, 2023

Yeah, I think so, cc @JukkaL (btw, thanks again for the change, it's a huge perf win for various codebases at work)

λ cat main.py
from third_party import awatch

async def main() -> None:
    async for i in awatch("/foo"):
        reveal_type(i)

λ cat third_party.py 
# mypy: ignore-errors
from typing import AsyncGenerator

async def awatch(path: str) -> AsyncGenerator[int, None]:
    if False:
        yield

Reminder to self: add aiohttp-devtools to mypy_primer

@hauntsaninja
Copy link
Collaborator

Okay, I have the fix

@Dreamsorcerer
Copy link
Contributor Author

Reminder to self: add aiohttp-devtools to mypy_primer

If you'd like some other aio-libs candidates, I'd suggest any of aiohttp-security, aiohttp-admin, aiohttp-jinja2, aiohttp-session and multidict.
I also noticed aioredis is in there, but that project has migrated to upstream redis now, so is no longer maintained.

JukkaL pushed a commit that referenced this issue Jun 23, 2023
hauntsaninja added a commit that referenced this issue Jun 24, 2023
@hauntsaninja
Copy link
Collaborator

Fixed and released in mypy 1.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-async async, await, asyncio
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants