inline configurations (mypy comments) in strings still work
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug Report
I take it the mypy inline configuration comments are supposed to work like regular hot comments, and not just activate whenever they appear as characters in the source file, such as in a string. However, as I discovered while investigating https://github.com/python/mypy/pull/17875#issuecomment-2939335586, they aren't actually parsed according to the Python syntax rules (because this would be slower and more complicated, at least given our current implementation) and therefore they do work if they're in a string, provided they are at the start of a line.
For example, in the following code, untyped defs are disallowed and an error is raised:
"""
This is just a silly little multi-line string literal, surely it couldn't—
# mypy: disallow-untyped-defs
"""
def foo():
return 1
Your Environment
- Mypy version used: this was probably 1.15, but I'd be surprised if it's been fixed by 1.17 (current as of time of writing)
Related
This, #12358, and https://github.com/python/mypy/issues/19366 form a loose family of "things we could easily fix if we had a parser that told us about comments to begin with" ie if https://github.com/python/mypy/pull/17875#issuecomment-2587759851 ¶2 or https://github.com/python/cpython/issues/101494#issuecomment-2395119743 were implemented.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el reproducer del issue y lee la documentación vinculada sobre la configuración inline, el issue #12358, el issue #19366, así como el pull request referenciado y la discusión de CPython. Se considera terminado cuando un comentario de configuración de mypy dentro de un string se ignora, mientras que el mismo comentario en comentarios reales del código fuente sigue funcionando.
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
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 30/100