-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Functional Python Programming, 3rd edition
By :

A common requirement is to customize a decorator with additional parameters. Rather than simply creating a composite f ∘ g(x), we can do something a bit more complex. With parameterized decorators, we can create f(c) ∘ g
(x). We’ve applied a parameter, c, as part of creating the wrapper, f(c). This parameterized composite function, f(c) ∘ g, can then be applied to the actual data, x.
In Python syntax, we can write it as follows:
@deco(arg)
def func(x):
base function processing...
There are two steps to this. The first step applies the parameter to an abstract decorator to create a concrete decorator. Then the concrete decorator, the parameterized deco(arg)
function, is applied to the base function definition to create the decorated function.
The effect is as follows:
concrete_deco = deco(arg)
def func(x):
base function processing...
&...