Skip to content

signature keeping wrapt decorator typing #304

@andythomas

Description

@andythomas

I did my best to type a wrapt decorator in a way that the original signature of the decorated function is still visible, but I was not able to do it. Some error always occurred. To my understanding, this is caused by:

@wrapt.decorator
def pass_through(wrapped, instance, args, kwargs):
    return wrapped(*args, **kwargs)

instead of

@wrapt.decorator
def pass_through(wrapped, instance, *args, **kwargs):
    return wrapped(*args, **kwargs)

According to ParamSpec and PEP612 the correct type information is

def with_request(f: Callable[Concatenate[Request, P], R]) -> Callable[P, R]:
  def inner(*args: P.args, **kwargs: P.kwargs) -> R:
    return f(Request(), *args, **kwargs)
  return inner

as an example. However, args: P.args raises an error. Does anyone have an idea/solution to this?

EDIT: Use better?! example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions