Copy call signature to decorator

Posted by Morgoth on Stack Overflow See other posts from Stack Overflow or by Morgoth
Published on 2010-06-06T03:10:44Z Indexed on 2010/06/06 3:12 UTC
Read the original article Hit count: 333

Filed under:
|

If I do the following

def mydecorator(f):
    def wrapper(*args, **kwargs):
        f(*args, **kwargs)
    wrapper.__doc__ = f.__doc__
    wrapper.__name__ = f.__name__
    return wrapper

@mydecorator
def myfunction(a,b,c):
    '''My docstring'''
    pass

And then type help myfunction, I get:

Help on function myfunction in module __main__:

myfunction(*args, **kwargs)
    My docstring

So the name and docstring are correctly copied over. Is there a way to also copy over the actual call signature, in this case (a, b, c)?

© Stack Overflow or respective owner

Related posts about python

Related posts about decorator