Skip to content

ParamSpec decorator incompatible with @overload #14040

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

Closed
Dreamsorcerer opened this issue Nov 8, 2022 · 1 comment
Closed

ParamSpec decorator incompatible with @overload #14040

Dreamsorcerer opened this issue Nov 8, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Nov 8, 2022

It seems like @overload is not working well with a decorator typed with Concatenate/ParamSpec.

Decorator is typed as:
def acquire(func: Callable[Concatenate[_Client, Connection, _P], Awaitable[_T]]) -> Callable[Concatenate[_Client, _P], Awaitable[_T]]:

The a method with overloads is like:

    @overload
    async def get(self, key: bytes) -> Optional[bytes]:
        ...

    @overload
    async def get(self, key: bytes, default: bytes) -> bytes:
        ...

    @acquire
    async def get(
        self, conn: Connection, key: bytes, default: Optional[bytes] = None
    ) -> Optional[bytes]:

Which then gives:

aiomcache/client.py:156: error: Overloaded function implementation does not accept all possible arguments of signature 1  [misc]
aiomcache/client.py:156: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]

If I move the @acquire before the first overload, then no type errors are produced (but, the code is now broken).

Code available at: https://github.com/aio-libs/aiomcache/blob/master/aiomcache/client.py#L159

@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Nov 8, 2022
@Dreamsorcerer
Copy link
Contributor Author

Oh, I already filed this bug 6 months ago: #12716.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant