June 2017
Beginner to intermediate
274 pages
6h 49m
English
If we were to modify our @ints_only decorator so that we could specify an arbitrary function that could be applied to all the parameters, it would look like the preceding example. So now we have a function called only, which returns a decorator, which in turn returns a wrapper. This wrapper calls the original function.
That might look terribly inefficient, but in fact the only overhead comes from invoking the wrapper. Each time we call the function, the outer two layers of code only run once when the function is defined. So that's how you use function decorators and taste the sort of things we can use them for.
Read now
Unlock full access