python / python/mypy

Coverage status reported for "not TYPE_CHECKING" blocks

Abierto
#6,101 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

priority-1-normal topic-usability
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

I'm not sure whether this qualifies as a bug, feature request or discussion.

I have a code base that I want to be able to run on Python 3.5 (the version in Debian stable at the moment), without introducing additional runtime dependencies (depending on typing_extensions while type checking is fine, but I don't want to force every end user to install it). Therefore, I made the following workaround for NoReturn:

# NoReturn was introduced in Python 3.6.5.
if TYPE_CHECKING:
	from typing_extensions import NoReturn
else:
	NoReturn = None

This works fine, both at runtime and when type checking. However, when I ask mypy to produce a coverage report, the NoReturn = None line shows up red.

Other code I put in the else body, for example a print statement, also shows up red. My guess is that mypy doesn't type check the else body because TYPE_CHECKING is True and then marks all code that it doesn't have information on as red.

I use the coverage report to see if there is anything regarding type hinting that can be improved in modules and these red lines from not TYPE_CHECKING blocks are noise that makes it harder to spot areas that could be improved. So for my use case, it would be better if blocks that are deliberately unchecked would be marked in either green or a new low-attention color like white or grey.

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

Empieza rastreando el manejo de los informes de cobertura de mypy para las ramas TYPE_CHECKING y comparando cómo se clasifica el cuerpo de else. El trabajo estará terminado cuando el código deliberadamente no comprobado en bloques not TYPE_CHECKING deje de aparecer como cobertura roja procesable, mientras que el código ordinario no cubierto siga siendo distinguible.

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

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
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.