Given a function:
def func(f1, kw='default'):
pass
bare_argspec = inspect.getargspec(func)
@decorator
def func2(f1, kw='default'):
pass
decorated_argspec = inspect.getargspec(func2)
How can I create a decorator such that bare_argspec == decorated_argspec
?
(As to why, the framework that calls the decorated function does argspec inspection to choose what to pass in, so the decorator has to retain the same argspec in order to play nice. When I posed this question on #python, I got a long speech about why the framework sucks, which is not what I'm looking for; I have to solve the problem here. Also, I'm just interested in the answer, too)
There's the decorator module:
That makes
trace
a decorator with the same argspecs as the decorated function. Example:Michele Simionato's decorator module has a decorator called decorator which preserves function argspecs.
Are
functools.update_wrapper()
and/orfunctools.wraps()
good enough?