Skip to content
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

Mypy should ensure overloads are compatible with the implementation #11086

Open
spagh-eddie opened this issue Sep 10, 2021 · 1 comment
Open

Comments

@spagh-eddie
Copy link

Bug Report

Mypy should ensure overloads are compatible with the implementation

To Reproduce

from typing import Union, overload
from typing_extensions import Literal

@overload
def f(*, flag: Literal[True]) -> float: ...
@overload
def f(*, flag: Literal[False] = False) -> str: ...
def f(*, flag: bool = False) -> Union[str, float]:
    return 5

reveal_type(f(flag=True))
reveal_type(f(flag=False))
reveal_type(f())

Expected Behavior

an error along the lines of "signature 2 incompatible with implementation" because it cannot return a str when flag=False

Actual Behavior

$ mypy test.py 
test.py:11:13: note: Revealed type is "builtins.float"
test.py:12:13: note: Revealed type is "builtins.str"
test.py:13:13: note: Revealed type is "builtins.str"

Your Environment

  • Mypy version used:
$ mypy --version
mypy 0.910
@KotlinIsland
Copy link
Contributor

Here's a minified example

from typing import overload

@overload
def func(i: int) -> int: ...
@overload
def func(i: str) -> str: ...
def func(i: str | int) -> str | int:
    return "AMONGUS"  # SUS ALERT! 

@AlexWaygood AlexWaygood added feature topic-overloads and removed bug mypy got something wrong labels Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants