Maintaining signature in help(decorated function)
Michele Simionato
michele.simionato at gmail.com
Wed Dec 10 11:21:01 EST 2008
On Dec 10, 5:07 pm, jelsas <jel... at gmail.com> wrote:
> 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!
You want the decorator module:
http://www.phyast.pitt.edu/~micheles/python/documentation.html
More information about the Python-list
mailing list