"Overloaded function signatures overlap with incompatible return types" false positive when there can be a subtype of both return types
Open
Nobody has claimed this yet.
bug
topic-overloads
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from typing import overload, Literal
class A: ...
class B: ...
class C(A, B): ...
@overload
def foo(a: Literal[True], b: Literal[True]) -> C: ...
@overload
def foo(a: Literal[True], b: bool) -> A: ... # error: Overloaded function signatures 2 and 3 overlap with incompatible return types [misc]
@overload
def foo(a: bool, b: Literal[True]) -> B: ...
def foo(a: bool, b: bool) -> object: ...
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 the minimal reproducer in the issue and inspect mypy's overload-overlap diagnostic for the three signatures involving A, B, and C. Confirm the behavior against the linked playground example, then add or update a regression test so compatible subtype return types no longer produce a false positive while genuine incompatible overlaps remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100