python / python/mypy

Error code for "async for" outside async function is too general

Abierto
#18,795 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug topic-async topic-error-reporting
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza reproduciendo el ejemplo de notebook percent-encoded proporcionado con mypy 1.15.0 y Python 3.12. Sigue cómo se asignan los diagnósticos para top-level await y async for y, a continuación, verifica que el error de async-for informe [top-level-await] como se espera, sin cambiar los diagnósticos de sintaxis no relacionados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
48/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.