Overload decorator lines classified as Unanalyzed
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
@overload decorator lines are classified as Unanalyzed in --lineprecision-report. The lineprecision ratio (Precise + Imprecise) / (Lines - Empty) therefore drops with every overload added, even when all signatures are fully annotated.
To Reproduce
# mre.py
from typing import Literal, overload
class C:
@overload
def f(self, x: Literal["a"]) -> str: ...
@overload
def f(self, x: Literal["b"]) -> int: ...
def f(self, x: Literal["a", "b"]) -> str | int:
return "hello" if x == "a" else 42
$ mypy mre.py --lineprecision-report report/
Success: no issues found in 1 source file
$ cat report/lineprecision.txt
Name Lines Precise Imprecise Any Empty Unanalyzed
-------------------------------------------------------
mre 10 6 0 0 2 2
Expected Behavior
Every line is fully annotated and mypy reports no errors, so the ratio should be 8/8 = 100%. The 2 Unanalyzed lines are the two @overload decorator lines. overload is a well-typed symbol from typing; those lines should be Precise (or at minimum Empty), treating @overload as a pure annotation marker with no runtime value.
Actual Behavior
StatisticsVisitor.process_node looks up each expression in self.typemap. The NameExpr for @overload is not populated in the typemap (mypy treats it as a special form during semantic analysis), so typemap.get(node) returns None → type(None) → record_line(TYPE_UNANALYZED).
Each overload variant therefore contributes 1 Precise line (the def) and 1 Unanalyzed line (@overload). Adding more fully-annotated overloads strictly lowers the ratio, making it impossible to hold a stable lineprecision gate on any file with a growing overload set.
There is a related # TODO in the same file: pass # TODO: Handle overloaded functions, etc. (in record_call_target_precision).
Your Environment
- Mypy version used: 2.1.0
- Mypy command-line flags:
--lineprecision-report - Python version used: 3.13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with StatisticsVisitor.process_node, where the issue reports that decorator expressions are classified through self.typemap, and review the related record_call_target_precision TODO in the same file. Run the supplied mre.py example with --lineprecision-report, then verify that the overload decorators no longer appear as Unanalyzed and the report reaches 8/8 precise lines.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100