12.5 Implementing more complex decorators
To create more complex compositions, Python allows the following kinds of function definitions:
@f_wrap
@g_wrap
def h(x):
return something...
Python permits stacking decorators that modify the results of other decorators. This has a meaning somewhat like f ∘g ∘h(x). However, the resulting name will be merely h(x), concealing the stack of decorations. Because of this potential confusion, we need to be cautious when creating functions that involve deeply nested decorators. If our intent is simply to handle some cross-cutting concerns, then each decorator should be designed to handle a separate concern while avoiding confusion.
While many things can be done with decoration, it’s essential to ask if using a decorator creates clear, succinct, expressive programming. When working with cross-cutting concerns, the features of the decorator are often essentially distinct from the function...