python - decorator - Setting a wrapped functions argument names and values -
is possible give wrapped function arg , kwargs names of function wrapping? need because decorators applied later use arg names of underlying function.
def wrapper(func): def wrapped(<func args , kwargs names , values>): return func(*args, **kwargs)
so if func been passed in foo(x,y=3), returned wrapped function have signature wrapped(x, y=3) instead of usual wrapped(*args, **kwargs).
--edit--
just found duplicate of preserving signatures of decorated functions . answers anyway
i'm not sure understand question, isn't expect ?
>>> def wrapper(func): def wrapped(*args, **kwargs): print args, kwargs return func(*args, **kwargs) return wrapped >>> @wrapper def foo(x, y=3): return x + y >>> foo(3) (3,) {} 6 >>> foo(3, 5) (3, 5) {} 8 >>> foo(3, y=5) (3,) {'y': 5} 8
Comments
Post a Comment