New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functionmaker.create (from doc example) fails with kwarg-only functions #139
Comments
Could from inspect import signature
from makefun import wraps
def foo(a, *, b, c=0):
return a + b * c
def dec(f):
def non_preserving_func(*args, **kwargs):
return f(*args, **kwargs)
return non_preserving_func
def decorator_apply(deco, func):
# use `makefun.wraps`
return wraps(func)(deco(func))
# The decorator was not preserving the signature
print(signature(dec(foo)))
# We make it preserve the signature
bar = decorator_apply(dec, foo)
print(signature(bar)) leads:
Hope this helps until this is fixed here. |
@smarie that does the trick, thanks! |
That example was written 10+ years ago and at the time signatures like def decorator_apply(dec, func):
return FunctionMaker.create( func, 'return decfunc(%(shortsignature)s)',
dict(decfunc=dec(func)), __wrapped__=func) Try this and let me know how it goes. Happy New Year! |
Even better if there is a direct solution @micheles ;) |
Awesome thanks! I totally get that the example predates the named parameter construction. Might be a good idea to either update the example in the docs or add it to the notes later in the readme. Happy new year! |
Already fixed the docs and made a release 5.1.1 ;-) |
Possibly related to #138 , but I'm creating a new issue here in case the root cause is fundamentally different.
I'm using the third-party decorator example like so:
I'm on decorator==5.1.0, python 3.9.9.
Is there a recommended workaround here? Or is there something more fundamental that will prevent this from working?
The text was updated successfully, but these errors were encountered: