You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I want other_decorator to capture the args passed to command for some reason, I have to implement other_decorator like this:
def other_decorator():
def dec(func):
def wrapped(*args, **kwargs):
# do something with args, kwargs
return func(*args, **kwargs)
return wrapped
return dec
However, adventurelib.when prevents this, since the signature of wrapped(*args, **kwargs) differs from the signature of command().
Ideally, the signature validation logic in _register would be able to detect that signatures are compatible, even if they're not identical. Failing that, can you add a mechanism to disable signature enforcement?
Also note that changing the order of decorators won't work, e.g.
@other_decorator
@when(...)
def command():
...
will not incorporate other_decorator into the registered function.
The text was updated successfully, but these errors were encountered:
In case this is still relevant: The wrapped function needs to be decorated with @functools.wraps(func) which makes the wrapper function to look like the wrapped function. That way, @when should not complain.
import functools
...
def other_decorator():
def dec(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
# do something with args, kwargs
return func(*args, **kwargs)
return wrapped
return dec
I would like to be able to do something like this:
If I want
other_decorator
to capture the args passed tocommand
for some reason, I have to implementother_decorator
like this:However,
adventurelib.when
prevents this, since the signature ofwrapped(*args, **kwargs)
differs from the signature ofcommand()
.Ideally, the signature validation logic in
_register
would be able to detect that signatures are compatible, even if they're not identical. Failing that, can you add a mechanism to disable signature enforcement?Also note that changing the order of decorators won't work, e.g.
will not incorporate
other_decorator
into the registered function.The text was updated successfully, but these errors were encountered: