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

Overload validation does not properly handle implied subtype relationships (e.g. int and float) #10143

Open
erictraut opened this issue Feb 26, 2021 · 1 comment
Labels
bug mypy got something wrong topic-overloads

Comments

@erictraut
Copy link

I'm working to make pyright's overload validation work consistently with mypy's.

Mypy's overload validation behavior is spec'ed here: python/typing#253 (comment)

As part of this validation, mypy reports errors when there is overlap between two overloads that return different return types. The following test case shows four such examples. Mypy properly reports the error in three of the four cases, but it misses the case where there is an implied subtype relationship, as between int and float.

# pyright: strict

from typing import Literal, Union, overload

class Parent: ...
class Child(Parent): ...

# Test 1: Literal subtype
@overload
def foo1(x: Literal[3]) -> int: ...
@overload
def foo1(x: int) -> str: ...

# Test 2: Subclass subtype
@overload
def foo2(x: Child) -> str: ...
@overload
def foo2(x: Parent) -> int: ...

# Test 3: Implicit subtype
@overload
def foo3(x: int) -> str: ...  # Mypy does not report error here
@overload
def foo3(x: float) -> int: ...

# Test 4: Union subtype
@overload
def foo4(x: int) -> str: ...
@overload
def foo4(x: Union[int, str]) -> int: ...
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 5, 2021

Yeah, we should treat int as a subtype of float here.

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

2 participants