python / python/mypy

Surprising results from the HTML report

Open
#21,168 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the supplied tmp.py example and uv run mypy --html-report tmp_dir tmp.py. Compare the HTML colors and hover text for the @overload, isinstance, and unreachable-code lines. Done means the report's visual indicators and hover descriptions consistently represent the detected Any usage and unreachable code.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.