compat.py 477 B

123456789101112131415161718
  1. import functools
  2. try:
  3. from decorator import decorator
  4. except ImportError:
  5. def decorator(caller):
  6. """ Turns caller into a decorator.
  7. Unlike decorator module, function signature is not preserved.
  8. :param caller: caller(f, *args, **kwargs)
  9. """
  10. def decor(f):
  11. @functools.wraps(f)
  12. def wrapper(*args, **kwargs):
  13. return caller(f, *args, **kwargs)
  14. return wrapper
  15. return decor