You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Asynchronous generator comprehensions such as (1 for f in futures if await f) are detected by mypy as regular synchronous generators.
I found a similar issue #12924 that has has been resolved by #12925, where expressions like (await f for f in futures) were being detected as regular synchronous generators instead of async ones. It looks like the fix didn't take into consideration that the await could be in the condition of the comprehension.
importasynciofromtypingimportAwaitable, AsyncGeneratorasyncdeffoo(*coros: Awaitable[None]) ->None:
gen= (Falseforfincorosifnotawaitf)
# Revealed type is "typing.Generator[builtins.bool, None, None]"# Runtime type is 'async_generator'reveal_type(gen)
returnawaitanext(gen)
asyncio.run(foo(asyncio.sleep(1), asyncio.sleep(2)))
Expected Behavior
Mypy should reveal the type as typing.AsyncGenerator.
Actual Behavior
Mypy reveals the type as typing.Generator
Your Environment
Mypy version used: 1.10.1
Python version used: 3.12
The text was updated successfully, but these errors were encountered:
Bug Report
Asynchronous generator comprehensions such as
(1 for f in futures if await f)
are detected by mypy as regular synchronous generators.I found a similar issue #12924 that has has been resolved by #12925, where expressions like
(await f for f in futures)
were being detected as regular synchronous generators instead of async ones. It looks like the fix didn't take into consideration that theawait
could be in the condition of the comprehension.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=80e893739ab1a8f98fd786da84b7e209
Expected Behavior
Mypy should reveal the type as
typing.AsyncGenerator
.Actual Behavior
Mypy reveals the type as
typing.Generator
Your Environment
The text was updated successfully, but these errors were encountered: