from functools import wraps
def my_decorator(f):
@wraps(f)
def wrapper(*args, **kwargs):
print('Calling decorated function')
return f(*args, **kwargs)
return wrapper
@decorator
def foo(*args, **kwargs):
pass
# translates to
foo = decorator(foo)
# So if the decorator had arguments,
@decorator_with_args(arg)
def foo(*args, **kwargs):
pass
# translates to
foo = decorator_with_args(arg, foo)