Skip to content

ParamSpec decorator incompatible with @overload #14040

@Dreamsorcerer

Description

@Dreamsorcerer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions