-
Notifications
You must be signed in to change notification settings - Fork 109
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
__code__ attribute no longer copied/passed through in decorator>=5 #129
Comments
Version 5 of the decorator module relies on the Signature object in the standard library which is a leaking abstraction and fails if one looks at low level objects like the |
I am adding the following function in version 5.1: def decoratorx(caller):
"""
A version of "decorator" implemented via "exec" and not via the
Signature object. Use this if you are want to preserve the `.__code__`
object properties (https://github.com/micheles/decorator/issues/129).
"""
def dec(func):
return FunctionMaker.create(
func,
"return _call_(_func_, %(shortsignature)s)",
dict(_call_=caller, _func_=func),
__wrapped__=func, __qualname__=func.__qualname__)
return dec Then things will work as you want if you define @decorator.decoratorx(decor)
def test(a, b, c=1, d=2):
pass However, rather than using |
For the record, |
Consider this simple example:
With decorator 4.4.2 I get:
With decorator 5.0.9 I get:
This breaks all my method decorators that I use with enthought traits library since they rely on func.code.co_argcount for trait change notification.
Is there a workaround I can do to my wrappers, without changing anything in the enthought traits library (like introducing inspect module there)?
The text was updated successfully, but these errors were encountered: