python / python/mypy

Surprising results from the HTML report

Aperta
#21,168 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il report con l’esempio tmp.py fornito e uv run mypy --html-report tmp_dir tmp.py. Confronta i colori HTML e il testo al passaggio del mouse per le righe con @overload, isinstance e codice irraggiungibile. Il lavoro è completato quando gli indicatori visivi e le descrizioni al passaggio del mouse del report rappresentano in modo coerente l’uso di Any rilevato e il codice irraggiungibile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.