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 decorated functions is that we can create composite functions. These are single functions that embody functionality from several sources. A composite function,
, can be somewhat more expressive of a complex algorithm than
. It's often helpful to have a number of syntax alternatives for expressing complex processing.
In this chapter, we'll look at the following topics:
- Using a decorator to build a function based on another function
- The
wraps()
function in thefunctools
module; this can help us build decorators - The
update_wrapper()
function, which may be helpful