python / python/mypy

"Overloaded function signatures overlap with incompatible return types" false positive when there can be a subtype of both return types

Open
#13,611 0 comments 4 reactions 0 assignees View on GitHub

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: ...

playground

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.