Skip to content

int | float ?= float inconsistency in Callable's return value ignores overlapping overloads #13775

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
twoertwein opened this issue Sep 29, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@twoertwein
Copy link

Bug Report

from typing import overload, Union, Callable, Any

Scalar = Union[int, float, complex]  # shows the error
# Scalar = complex  # hides the error

class A: ...
class B: ...

@overload
def apply(self, func: Callable[[A], Scalar]) -> B: ...

# error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]
@overload
def apply(self, func: Callable[[Any], float]) -> A: ...

Expected Behavior

In both cases the overloads should be overlapping.

Your Environment

  • Mypy version used: 0.971 and 0.981
  • Python version used: 3.10
@twoertwein twoertwein added the bug mypy got something wrong label Sep 29, 2022
@emmatyping
Copy link
Member

I'm not sure I agree about the expected behavior, if you pass a function Callable[[A], complex] to apply, if Scalar = complex then only the first overload can apply, in other words they are not overlapping.

@twoertwein
Copy link
Author

I'm not sure I agree about the expected behavior, if you pass a function Callable[[A], complex] to apply, if Scalar = complex then only the first overload can apply, in other words they are not overlapping.

Thank you - I agree, when changing Scalar = float it also errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants