python / python/mypy

Surprising results from the HTML report

Abierto
#21,168 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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

I was able to replicate your problems on mypy master (mypy 2.0.0+dev.3cda6ec255a530e7da8bec44d197399aec73e96d (compiled: no)), such as the @overload thing. I think this is a bug, especially considering that the typeshed definition of overload does not contain Any, but it is hard for me to say definitively (due to the lack of documentation).

With the following code:

from typing import overload

def foo(x):
    return x

def foo1(x: int) -> int:
    return x

def foo2(x) -> int:
    return x

def foo3(x: int):
    return x

def foo4(x: int):
    return x

@overload
def foo5(x: int) -> int: ...
@overload
def foo5(x: str) -> str: ...
def foo5(x):
    return x

@overload
def foo6(x: int) -> int: ...
@overload
def foo6(x: str) -> str: ...
def foo6(x: int|str) -> int|str:
    return x

And the following command:

uv run mypy --html-report tmp_dir tmp.py

I get the following result:

Image

The @overload lines are red but on hover say "No Anys on this line!". Surprisingly, this is also true of def foo(x): and def foo5(x):

My isinstance lines are always colored green, not yellow. In fact, the line isinstance(1,list) is green, but on hover it says Any Types on this line: Omitted Generics (x3). I think this kind of makes sense as behavior given the rules about isinstance but I think in that case the hovertext should maybe be different.

In the following code, the print("OK") line is colored red despite on hover saying No Anys on this line!. The if isinstance(v,list): line is green despite saying Any Types on this line: Omitted Generics (x3)

v = 1
if isinstance(v,list):
    print("OK")

Possibly related: https://github.com/python/mypy/issues/14297

Originally posted by @wyattscarpenter in #13495

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

Reproduce el informe con el ejemplo tmp.py proporcionado y uv run mypy --html-report tmp_dir tmp.py. Compara los colores HTML y el texto al pasar el cursor por las líneas de @overload, isinstance y código inalcanzable. Se considera terminado cuando los indicadores visuales y las descripciones al pasar el cursor del informe representan de forma coherente el uso de Any detectado y el código inalcanzable.

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
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.