await-not-async missed & false alarms with genexp and list comprehensions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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 https://github.com/astral-sh/ruff/issues/14167 that had the exact same issues
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando l'implementazione di await-not-async e la gestione di GeneratorExp.elt, delle list comprehension e delle dict comprehension. Riproduci l'esempio fornito con mypy, quindi verifica che vengano emesse diagnosi alle righe 8, 9, 12 e 13, mentre i casi di espressioni generatrici alle righe 5 e 14 non generino avvisi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 58/100