-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as not planned
Closed as not planned
Copy link
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
MyPy thinks bool and int parameter signatures overlap (apparently as they're assignable), although it doesn't think the same about int and float (which are equally assignable, though not subtype).
To Reproduce
@overload
def test(b: bool, /) -> Literal['bool']: ... # Mypy error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
@overload
def test(n: int, /) -> Literal['int']: ...
@overload
def test(x: float, /) -> Literal['float']: ... # Mypy accepts
def test(x: float, /) -> Literal['bool', 'int', 'float']:
match x:
case bool(): return 'bool'
case int(): return 'int'
case float(): return 'float'
case _: assert_never(x)Expected Behavior
I expected MyPy to accept this (runtime works).
Actual Behavior
However, MyPy reports:
# error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
Changing the 2nd overload into def test(n: int, /) -> Literal['bool', 'int'] removes the superfluous error, but doesn't express the code's intent.
Potential Duplicates
Reported issues #11165 and #20084 look similar, but sufficiently different that I cannot conclude they're the same (root) issue.
Your Environment
- Mypy version used: 1.19.1 from PyPI
- Mypy command-line flags: both with and without
--strict - Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.15.0a6, 3.14.3, 3.13.12 on Windows 11
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong