12 Decorator Design Techniques
Python offers us many ways to create higher-order functions. In Chapter 5, Higher-Order Functions, we looked at two techniques: defining a function that accepts a function as an argument, and defining a subclass of Callable, which is either initialized with a function or called with a function as an argument.
One of the benefits of decorating functions is that it can create composite functions. These are single functions that embody functionality from several sources. It’s often helpful to have the decoration syntax as a way to express complex processing.
We can also use decorators to identify classes or functions, often building a registry—a collection of related definitions. We may not necessarily create a composite ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access