python / python/mypy

Support warning on unused ignores without treating them as an error

Abierto
#12,359 1 comentario 14 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature topic-type-ignore
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Feature

Mypy's --warn-unused-ignores option currently treats unused ignores as an error, rather than merely warning about them but still exiting zero.

Mypy should support an option where unused ignores are still warned about in the output, but are not treated as an error.

Current behavior:

❯ cat test.py
x = 1 + 1  # type: ignore

❯ mypy test.py
Success: no issues found in 1 source file

❯ mypy --strict test.py  # exits nonzero
test.py:1: error: Unused "type: ignore" comment
Found 1 error in 1 file (checked 1 source file)

❯ mypy --strict --no-warn-unused-ignores test.py  # exits zero
Success: no issues found in 1 source file

The current warn-unused-ignores behavior, where you have to choose between either erroring or total silence when there's an unused ignore (and can't actually just get a warning), could even be considered a bug.

Pitch

To preserve backward compatibility, perhaps something like this would work:

❯ mypy --unused-ignores=warning # emit a warning but don't exit nonzero

❯ mypy --unused-ignores=error # emit an error and exit nonzero, same as --warn-unused-ignores now

❯ mypy --warn-unused-ignores # same as --unused-ignores=error

❯ mypy --unused-ignores=none # no output, exit zero, same as --no-warn-unused-ignores now

❯ mypy --no-warn-unused-ignores # same as --unused-ignores=none

And the mypy -h usage output would just steer people toward using the new, less confusing options. Potentially using the old options could emit a message like "This option is deprecated, please use <new option> instead", if we may want to remove the confusing options at some point in the future.

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 con el procesamiento de la línea de comandos ilustrado por los ejemplos de --warn-unused-ignores y sigue cómo los diagnósticos de ignoraciones no utilizadas afectan al estado de salida. Define los modos de advertencia, error y deshabilitado conservando los flags existentes; después, añade cobertura para cada comportamiento de la línea de comandos y verifica las salidas y los códigos de salida documentados.

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

Evaluación

Stack tecnológico
python
Área
cli, tooling
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.