Skip to content

Can't seem to type a decorator that works with ParamSpec on methods #16333

@Dreamsorcerer

Description

@Dreamsorcerer

I've been struggling with this one, and I'm not sure if I'm doing something wrong or mypy is doing something wrong:

from typing import Callable, Generic, ParamSpec, TypeVar

P = ParamSpec("P")
R = TypeVar("R")

class A(Generic[P, R]):
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...

def decorator(fn: Callable[P, R]) -> A[P, R]: ...

class B:
    @decorator
    def foo(self) -> None: ...


b = B()
b.foo()  # error: Missing positional argument "self" in call to "__call__" of "A"  [call-arg]

I need the decorator, which returns the A wrapper, to work with both functions and methods.

Full project is at: aio-libs/async-lru#508

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