Description:
- Make it easy to define signature-preserving function decorators and decorator factories.
Resources:
- [GitHub] https://github.com/micheles/decorator
- [Docs] https://github.com/micheles/decorator/blob/master/docs/documentation.md
Example 1
Section titled “Example 1”Create a simple decorator to trace a function
from inspect import getfullargspecfrom decorator import decorate
def _trace(f, *args, **kw): kwstr = ', '.join('%r: %r' % (k, kw[k]) for k in sorted(kw)) print("calling %s with args %s, {%s}" % (f.__name__, args, kwstr)) return f(*args, **kw)
def trace(f): return decorate(f, _trace)
@tracedef f1(x): pass
print(f1(0))
# Verifyprint(getfullargspec(f1))ganymede is made by Eugo