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

Incompatible override of overloaded function not caught #3189

Closed
JelleZijlstra opened this issue Mar 13, 2022 · 2 comments
Closed

Incompatible override of overloaded function not caught #3189

JelleZijlstra opened this issue Mar 13, 2022 · 2 comments
Labels
as designed Not a bug, working as intended

Comments

@JelleZijlstra
Copy link
Contributor

JelleZijlstra commented Mar 13, 2022

On current Pylance/Pyright, I get no errors on this file:

from typing import Generic, TypeVar, Union, overload, Any

VT = TypeVar("VT")
T = TypeVar("T")


class X(Generic[VT]):
    @overload
    def pop(self) -> VT:
        ...

    @overload
    def pop(self, __default: Union[VT, T]) -> Union[VT, T]:
        ...

    def pop(self, __default: Any = None) -> Any:
        ...


class Child(X[VT]):
    def pop(self, __default: VT) -> VT:
        ...


class Child2(X[VT]):
    @overload
    def pop(self) -> VT:
        ...

    @overload
    def pop(self, __default: VT) -> VT:
        ...

    def pop(self, __default: Any = None) -> Any:
        ...

But both Child and Child2 override pop incompatibly. (Found this in jab/bidict#242 (comment) )

@erictraut
Copy link
Collaborator

Pyright intentionally doesn't do any override validation when overloads are involved. There's really no good way (as far as I know) to determine whether one set of overloads is compatible with another. So rather than risk false positive errors, pyright doesn't attempt to detect override compatibilities in this case.

@erictraut erictraut added the as designed Not a bug, working as intended label Mar 13, 2022
@JelleZijlstra
Copy link
Contributor Author

Interesting, I hadn't realized that. I don't know what mypy does internally, but in pyanalyze for checking the compatibility of two overloaded signatures L and R, I check that R is compatible with all of the component signatures in L.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended
Projects
None yet
Development

No branches or pull requests

2 participants