Allow ignore to be on any line of multi-line statement
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
Feature
Currently, comments can be added to a line to ignore either all errors (# type: ignore), or a specific error code (eg. # type: ignore[call-arg]). When a single statement spans multiple lines, the comment has to be added on the line that mypy "decides" is the one with the error (is it the first line of the expression, rather than first line of the statement?). In some cases, it would make sense to allow the comment to be on a different line of the same statement. I propose allowing it to be on any line of the statement, and therefore to apply to the whole statement.
Pitch
Sometimes it makes more sense for it to be another line, such as when importing something that mypy thinks does not exist, it makes sense to have the ignore on the same line as the attribute that is reported as not existing.
from typing import ( # ignore currently needs to be here
Union,
DoesNotExist, # type: ignore[error attr-defined]
)
Sometimes, a formatter like black changes a long line into a multiple line statement. The comment that was at the end of the line is moved to the end of the last line.
def foo(bar:int) -> str: ...
def baz() -> int: ...
a = ( # type: ignore[call-arg]
"something"
if baz() > 0 else
foo() # ignore currently needs to be here
) # formatters (eg. black) often put ignore here
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
Empieza con los dos ejemplos multilínea y la reproducción vinculada de mypy-play; sigue cómo mypy asocia los comentarios type: ignore con las sentencias. Se considera terminado cuando un ignore en cualquier línea de una misma sentencia multilínea suprime el error relevante de esa sentencia, incluidos los códigos específicos, sin cambiar el comportamiento de las sentencias separadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100