Given a list of decorator methods, how would one apply those to a callable?
For example, since:
@foo
@bar
def baz():
pass
…is the same as:
def baz():
pass
baz = foo(bar(baz)))
…one would assume that with a list of decorators ([foo, bar]) they could be applied to baz dynamically.
With yet another decorator!
example usage
Without the decorator syntax, it would look like
If you wanted to apply the same list to multiple functions, you can do it like:
As recursive points out in the comments, you can define
yad(I’m sure there’s a better name for this) to accept*decoratorsinstead ofdecorators. Then you don’t have to use brackets if you’re creating the list in situ. The way that I’ve demonstrated is better if the list is created elsewhere.