How to add type annotations to a decorator for a class instance method that has been decorated with functools.wraps?

48 Views Asked by At
P = ParamSpec("P")
R = TypeVar("R")

def deco(func: Callable[Concatenate[R, int, int,  P], None]):
    @functools.wraps(func)
    def wrapper(self, *args: P.args, **kwargs: P.kwargs):
        return func(self, 1, 2, *args, **kwargs)
    return wrapper


class A:
    @deco
    def main(self, a, b, c):
        pass


a = A()
a.main(3)

Last line of code, pyright gives me an error message: Argument missing for parameter "c"

It is ok when I remove the @functools.wraps(func)

How to solve this error message while keeping @functools.wraps(func)?

Thanks in advance

The code structure cannot be changed, so I actually can't try anything, and I have no idea.

0

There are 0 best solutions below