Effective Decorators—Avoiding Common Mistakes
Learn how to avoid common side effects when using decorators.
We'll cover the following
While decorators are a great feature in Python, they are not exempt from issues if used incorrectly. Let's look at some common issues to avoid in order to create effective decorators.
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, let's look at a decorator that is in charge of logging when the function is about to run:
Get hands-on with 1400+ tech skills courses.