Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
henzef opened this issue Feb 23, 2023 · 1 comment
Labels
bug mypy got something wrong topic-overloads

Comments

@henzef
Copy link

henzef commented Feb 23, 2023

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
@sterliakov
Copy link
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
Labels
bug mypy got something wrong topic-overloads
Projects
None yet
Development

No branches or pull requests

3 participants