Error code for "async for" outside async function is too general
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Merge moyen
- 1 j 18 h
- PR mergées (30 j)
- 54
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire l’exemple de notebook percent-encoded fourni avec mypy 1.15.0 et Python 3.12. Suivez la manière dont les diagnostics pour top-level await et async for sont attribués, puis vérifiez que l’erreur async-for signale [top-level-await] comme prévu, sans modifier les diagnostics de syntaxe non liés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- tooling
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 48/100