3 ms·
Decorators by themselves are easy. @foo def bar: ... is just syntactic sugar for def bar: ... bar = foo(bar) The hard part is first-class fu
by qznc 14y ago
Decorators by themselves are easy.
@foo
def bar:
...
is just syntactic sugar for
def bar:
...
bar = foo(bar)
The hard part is first-class functions and what you can do with them and what you should not do with them.
- camus 14y agobut what about @foo('baz') def bar: a bit more complicated to understand imho
- falcolas 14y agoOnly a little: bar = foo('baz')(bar) [EDIT]: Basically, whatever function is returned from the decorator line (the function itself, if there is no call, or the results from a function call otherwise) is applied to the decorated function.