Open
Description
Bug Report
await-not-async does not warn on async for
in list and dict comprehensions, and incorrectly does give a warning for await
inside GeneratorExp.elt
.
For list & dict comprehensions you should error on any await
or async for
, but for generator expressions it's only the generator that should be checked.
To Reproduce
def foo():
...
def should_not_error():
(await x for x in foo())
def should_error():
[x async for x in foo()]
{k: v async for k, v in foo()}
def correctly_errors():
(x for x in await foo())
[await x for x in foo()]
def correctly_does_not_error():
(x async for x in foo())
Expected Behavior
It should error on 8, 9, 12 and 13
Actual Behavior
$ mypy foofoo.py
foofoo.py:5: error: "await" outside coroutine ("async def") [await-not-async]
foofoo.py:12: error: "await" outside coroutine ("async def") [await-not-async]
foofoo.py:13: error: "await" outside coroutine ("async def") [await-not-async]
Found 3 errors in 1 file (checked 1 source file)
Your Environment
$ mypy --version
mypy 1.13.0 (compiled: yes)
- Mypy version used:
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini
(and other config files): - Python version used:
also see astral-sh/ruff#14167 that had the exact same issues