In Decorator: Basics, we have seen the basics of decorators. import functools def decorator(func): @functools.wraps(func) def wrapper_decorator(*args, **kwargs): # Do something before value = func(*args, **kwargs) # Do something after return value return wrapper_decorator The key is to remember the following two expressions are equivalent (the latter uses the syntactic sugar):
2022-05-23
TL;DR Decorators define reusable building blocks you can apply to a callable to modify its behavior without permanently modifying the callable itself. The @ syntax is just a shorthand (syntax sugar) for calling the decorator on an input function.
2022-05-21