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

Overlapping overload check differs from mypy in some cases #1546

Closed
erictraut opened this issue Feb 26, 2021 · 3 comments
Closed

Overlapping overload check differs from mypy in some cases #1546

erictraut opened this issue Feb 26, 2021 · 3 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@erictraut
Copy link
Collaborator

Pyright's checks for overlapping overloads differs in some ways from mypy's. That inconsistency is causing problems for typeshed checking. Pyright should be consistent with mypy in this case.

Here are some examples:

# pyright: strict

from typing import Literal, TypeVar, Union, overload
@overload
def foo1(x: int) -> int: ...
@overload
def foo1(x: float) -> int: ...

# Mypy: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader
# Pyright: Overload 2 for "foo2" will never be used because its parameters overlap overload 1
@overload
def foo2(x: float) -> int: ...
@overload
def foo2(x: int) -> int: ...

# Mypy: Overloaded function signatures 1 and 2 overlap with incompatible return types
# Pyright: Overload 1 for "foo3" overlaps overload 2 and returns an incompatible type
@overload
def foo3(x: Literal[3]) -> int: ...
@overload
def foo3(x: int) -> str: ...

# Mypy: No error
# Pyright: Overload 1 for "foo4" overlaps overload 2 and returns an incompatible type
@overload
def foo4(x: int) -> int: ...
@overload
def foo4(x: float) -> str: ...

# Mypy: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader
# Pyright: No error
_T = TypeVar("_T")
@overload
def foo5(x: _T) -> Union[int, _T]: ...
@overload
def foo5(x: int) -> str: ...
@erictraut erictraut added the bug Something isn't working label Feb 26, 2021
@erictraut
Copy link
Collaborator Author

The spec for mypy's behavior can be found here: python/typing#253 (comment)

@erictraut
Copy link
Collaborator Author

I've fixed two bugs in pyright and reported one bug in mypy (python/mypy#10143). The two bugs in pyright will be fixed in the next release.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Feb 26, 2021
@erictraut
Copy link
Collaborator Author

This is addressed in pyright 1.1.116, which I just published. It will also be in the next release of pylance.

heejaechang added a commit to heejaechang/pyright that referenced this issue Nov 3, 2021
* initial implementation of dic key completion

* refactoring dict key function to 2

* some refactoring and fixed all test failures

* handle string literal key case better

* filter out duplicated keys

* added some basic test coverage

* use proper sort text for dict keys.

* added tests for dict keys

* added one more edge case.

* removed tests left over after moving

* PR feedback, renamed method name

* found a bug where we didn't handle type annotation case correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant