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

Wrong "Overloaded function implementation does not accept all possible arguments" #11004

Open
dvarrazzo opened this issue Aug 21, 2021 · 6 comments · May be fixed by #10390
Open

Wrong "Overloaded function implementation does not accept all possible arguments" #11004

dvarrazzo opened this issue Aug 21, 2021 · 6 comments · May be fixed by #10390
Labels
bug mypy got something wrong topic-overloads

Comments

@dvarrazzo
Copy link

Bug Report

The following example (reduced from psycopg 3) seems to be a false positive:

To Reproduce

from typing import Any, Callable, Generic, overload, Optional, TypeVar, Tuple, Union

Row = TypeVar("Row")

class Connection(Generic[Row]):
    @overload
    def connect(
        self, *, row_factory: Callable[[], Row], **kwargs: Union[None, int, str]
    ) -> "Connection[Row]":
        ...

    @overload
    def connect(
        self, **kwargs: Union[None, int, str],
    ) -> "Connection[Tuple[Any, ...]]":
        ...

    def connect(
        self, *, row_factory: Optional[Callable[[], Row]] = None, **kwargs: Any,
    ) -> "Connection[Any]":
        raise NotImplementedError

The file is flagged with the error:

bug_mypy.py:18: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]

Your Environment

  • Mypy version used: 0.910
  • Python version used: 3.8
  • Operating system and version: Linux
@dvarrazzo dvarrazzo added the bug mypy got something wrong label Aug 21, 2021
@erictraut
Copy link

You may have already figured this out, but there is a simple workaround. If you change the second overload to include an explicit row_factory parameter, it will type check without errors.

    @overload
    def connect(
        self,
        *,
        row_factory: None = None,
        **kwargs: Union[None, int, str],
    ) -> "Connection[Tuple[Any, ...]]":
        ...

@dvarrazzo
Copy link
Author

dvarrazzo commented Aug 21, 2021

@erictraut No, I didn't notice that, thank you. It is interesting, however I prefer to use a type: ignore rather than a dummy parameter.

Another thing that makes the error go is to use **kwargs: Any in the second signature.

@dlax
Copy link
Contributor

dlax commented Aug 23, 2021

I think that's the issue I tried to resolve in #10390.

@dvarrazzo
Copy link
Author

dvarrazzo commented Aug 23, 2021

Amazing @dlax, didn't know you had looked into it so much to propose a MR! 🙂

@adam-grant-hendry
Copy link

@dlax Do you plan to merge the change soon?

@dlax
Copy link
Contributor

dlax commented Jul 6, 2022

@adam-grant-hendry, the PR is still pending review; and then possible merge by a project member.

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

Successfully merging a pull request may close this issue.

5 participants