While decorators are a great feature of Python, they are not exempt from issues if used incorrectly. In this section, we will see some common issues to avoid in order to create effective decorators.
Effective decorators – avoiding common mistakes
Preserving data about the original wrapped object
One of the most common problems when applying a decorator to a function is that some of the properties or attributes of the original function are not maintained, leading to undesired, and hard-to-track, side-effects.
To illustrate this we show a decorator that is in charge of logging when the function is about to run:
# decorator_wraps_1.py
def trace_decorator(function):
def wrapped(*args, **kwargs):
logger.info("...