GrahamDumpleton / wrapt

A Python module for decorators, wrappers and monkey patching.
BSD 2-Clause "Simplified" License
2.03k stars 231 forks source link

Functions with `synchronized` decorator doesn't preserved its typing signature #230

Open alonp123 opened 1 year ago

alonp123 commented 1 year ago

I'm using the amazing wrapt.synchronized decorator, but I've just realized that it breaks the typing signature of the wrapped function (using vscode). I tested it with custom wrapt.decorator function and it works fine. Does someone have a solution?

Example:

import wrapt 

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

@pass_through
def function(arg):
    print(arg)

@wrapt.synchronized
def synced_function(arg):
    print(arg)

The function signature:

image

The synced_function signature:

image
GrahamDumpleton commented 1 year ago

See https://github.com/GrahamDumpleton/wrapt/issues/164 and https://github.com/GrahamDumpleton/wrapt/pull/225. I still haven't got to properly understanding the types annotation mechanism in order to integrate suggested change.