3 ms·
You can use the `functools.wraps` decorator to deal with copying all (most) metadata from the wrapped function: def trace(fn): @functools.wraps(fn)
by lclarkmichalek 13y ago
You can use the `functools.wraps` decorator to deal with copying all (most) metadata from the wrapped function:
def trace(fn):
@functools.wraps(fn)
def worker(*args):
logging.info('Called %s with args %r', fn.__name__, args)
return fn(*args)
return worker
Docs: http://docs.python.org/3/library/functools.html#functools.wraps http://docs.python.org/3/library/functools.html#functools.wr...
- darth_aardvark 13y agoI've been looking for something exactly like this. It's so tedious trying to remember what metadata needs to be copied from a function when making a decorator. Thanks!