Maintaining signature in help(decorated function)

J

jelsas

Hi -- I can't seem to maintain the function signature when applying a
decorator. I'm using functools.wraps. Example:
.... from functools import wraps
.... # simple decorator
.... @wraps(fn)
.... def wrapped(*args, **kwargs):
.... print 'i\'m wrapped!'
.... return fn(*args, **kwargs)
.... return wrapped
........ def f(foo, bar):
.... '''docstring for f'''
.... pass
....
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!
 
M

Michele Simionato

Hi -- I can't seem to maintain the function signature when applying a
decorator.  I'm using functools.wraps.  Example:


...     from functools import wraps
...     # simple decorator
...     @wraps(fn)
...     def wrapped(*args, **kwargs):
...             print 'i\'m wrapped!'
...             return fn(*args, **kwargs)
...     return wrapped
...


... def f(foo, bar):
...     '''docstring for f'''
...     pass
...




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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top