12.3 Composite design
The common mathematical notation for a composite function looks as follows:
The idea is that we can define a new function, f ∘g(x), that combines two other functions, f(y) and g(x).
Python’s multiple-line definition of a composition function can be done through the following code:
@f_deco
def g(x):
something
The resulting function can be essentially equivalent to f ∘ g(x). The @f_deco
decorator must define and return the composite function by merging an internal definition of f(y) with the provided base function, g(x).
The implementation details show that Python actually provides a slightly more complex kind of composition. The structure of a wrapper makes it helpful to think of Python decorator composition as follows:
A decorator applied to some application function, g(x), will include a wrapper function, w(y), that has two parts. One portion of the wrapper, wα(y), applies to the arguments of...