Check for return type of overload implementation is too strict?
Open
Nobody has claimed this yet.
false-positive
needs discussion
priority-1-normal
topic-overloads
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Consider this simplified example:
from typing import overload, Optional, List
@overload
def f(x: int) -> List[int]: ...
@overload
def f(x: None) -> List[Optional[int]]: ...
def f(x: Optional[int]) -> List[Optional[int]]:
return [x]
Mypy currently complains about it that:
Overloaded function implementation cannot produce return type of signature 1
Although I understand why this happens, it is a bit annoying and can be perceived as a false positive. Maybe we should use is_overlapping_types() instead of is_subtype() for the check?
cc @Michael0x2a
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 simplified overload example and trace the implementation return-type check in mypy. Compare the current is_subtype() check with the proposed is_overlapping_types() behavior, then determine whether the example should be accepted and validate the decision with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100