Overlapping overload detection fails when signature contains TypeVar
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Mypy detects and reports overlapping function overloads that differ in return type.
In the example below, it correctly reports that the second overload of func1 overlaps the first overload. However, when the concrete type str is replaced by a generic type _T, it fails to report the error.
@overload
def func1(
a: str,
b: Literal[False] = ...,
) -> List[str]: ...
@overload
def func1(
a: str,
b: bool = ...,
) -> List[Union[str, int]]: ...
_T = TypeVar("_T")
@overload
def func2(
a: _T,
b: Literal[False] = ...,
) -> List[_T]: ...
@overload
def func2(
a: _T,
b: bool = ...,
) -> List[Union[_T, int]]: ...
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 running the two overload examples from the issue through mypy and compare the diagnostics for func1 and func2. Then trace the overload-overlap detection path responsible for these diagnostics. Done means mypy reports the overlapping overloads in the TypeVar-based func2 example without regressing the concrete case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100