Maintaining signature in help(decorated function)
jelsas
jelsas at gmail.com
Wed Dec 10 11:07:14 EST 2008
Hi -- I can't seem to maintain the function signature when applying a
decorator. I'm using functools.wraps. Example:
>>> def mydecorator(fn):
... from functools import wraps
... # simple decorator
... @wraps(fn)
... def wrapped(*args, **kwargs):
... print 'i\'m wrapped!'
... return fn(*args, **kwargs)
... return wrapped
...
>>>
>>> @mydecorator
... def f(foo, bar):
... '''docstring for f'''
... pass
...
>>>
>>> help(f)
displays:
Help on function f in module __main__:
f(*args, **kwargs)
docstring for f
I would like to maintain f's signature in the help message, (foo, bar)
instead of (*args, **kwargs)
Thanks in advance!
More information about the Python-list
mailing list