Skip to content

False-positive "Overloaded function signatures overlap with incompatible return types" #14770

Closed

Description

@henzef

Bug Report

In the minimal example below, I get an unexpected "Overloaded function signatures overlap with incompatible return types" error from mypy. The example is taken from a general "wait for an event or a message" function that I use in my codebase. It allows requesting one or multiple event or message types.

To Reproduce

class Message:
    pass


class Event:
    pass


_WaitableTypes = Union[type[Message], type[Event]]
_MessageT1 = TypeVar("_MessageT1", bound=Message)
_MessageT2 = TypeVar("_MessageT2", bound=Message)


# Single message
@overload
def wait_for(
    msg_type: type[_MessageT1],
) -> _MessageT1:
    ...


# Two messages (arbitrary iterable of messages is also supported, but not relevant in this example)
@overload
def wait_for(
    msg_type: tuple[type[_MessageT1], type[_MessageT2]],
) -> Union[_MessageT1, _MessageT2]:
    ...


# List of events
@overload
def wait_for(
    msg_type: Iterable[type[Event]],
) -> Event:
    ...


def wait_for(
    msg_type: Union[_WaitableTypes, Iterable[_WaitableTypes]],
) -> Union[Message, Event]:
    return ...  # type: ignore

Expected Behavior

mypy does not complain

Actual Behavior

mypy reports "error: Overloaded function signatures 2 and 3 overlap with incompatible return types [misc]"

Your Environment

  • Mypy version used: 1.0.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9

Activity

  1. sterliakov commented on Jan 22, 2025

    @sterliakov
    Collaborator

    Fixed via #17392 (since mypy 1.11.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions