Mypy should report why each possible overload doesn't match
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Feature
Currently when no overload is valid for a function call mypy just lists the overloads with no explanation for why each one doesn't work:
No overload variant of "target" matches argument types "TargetType", "str", "ClobberConfig" [call-overload]
Possible overload variants:
def target(*, typ: TargetType, path: str | Path) -> Target[NoConfig]
def target(*, target_path: TargetPath) -> Target[NoConfig]
def [ConfigT <: Config] target(*, target_path: TargetPath, config: ConfigT) -> Target[ConfigT]
def [ConfigT <: Config] target(*, typ: TargetType, path: str | Path, config: ConfigT) -> Target[ConfigT]
Pitch
However, in this scenario I've manually verified that the last overload really should work. It's possible that it's a mypy bug, or it's possible that my reasoning is wrong, but if my reasoning is wrong it would be way more obvious if mypy told me why it's rejecting the overload I think should be accepted (the last one in this case). There's precedent too, C++ compilers nowadays do this for overloads and it greatly helps with understanding more complex (especially Generic) code.
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 by reproducing the sample overloaded call and inspect mypy's overload-resolution diagnostics. Trace where the "Possible overload variants" message is produced; done means reporting why each candidate is rejected, while retaining the existing behavior when an overload matches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100