Reputation:
What is a function decorator? Is it something we use to declare a function? Or is it like a constructor.
Upvotes: 1
Views: 660
Reputation: 531798
A function decorator is simply a function intended to take a function as an argument and return a new function to use in its place. Python provides decorator syntax to simply its use. That is,
@foo
def bar():
pass
is equivalent to
def bar():
pass
bar = foo(bar)
The syntax takes care of applying the decorator to the original function and rebinding the result to the original name.
Upvotes: 1