Error code for "async for" outside async function is too general
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
The error code for "async for" outside async function [syntax] is very general, so it is hard to disable without allowing other syntax errors.
This is important to me because I want to type check Jupyter notebooks that take advantage of the autoawait feature and are written in the percent file format. With the error code being syntax, I would have to allow many unrelated errors to disable this error using disable_error_code.
I think it would be good if it used the same error code as "await" outside function [top-level-await], or perhaps a new code entirely.
To Reproduce
Example percent encoded notebook:
# %%
async def foo():
return 1
await foo()
# %%
async def values():
yield 1
yield 2
async for v in values():
print(v)
https://mypy-play.net/?mypy=latest&python=3.12&gist=ddd45a5b59946d0b423e5494af96e286
Expected Behavior
main.py:6: error: "await" outside function [top-level-await]
main.py:15: error: "async for" outside async function [top-level-await]
Actual Behavior
main.py:6: error: "await" outside function [top-level-await]
main.py:15: error: "async for" outside async function [syntax]
Your Environment
- Mypy version used: 1.15.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.12.9
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 riproducendo l'esempio di notebook percent-encoded fornito con mypy 1.15.0 e Python 3.12. Traccia come vengono assegnate le diagnosi per top-level await e async for, quindi verifica che l'errore async-for riporti [top-level-await] come previsto, senza modificare le diagnosi di sintassi non correlate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100