Python Decorators (and Digressions)
Decorators are a bit of meta-programming that allows one to add behaviour to functions and classes. The original function or class is wrapped in another function or class, and its name is pointed to that wrapper. Any use of that name will refer to the wrapper, not the original. This happens at “compile” time, not at runtime
The mechanics treat any function or class name prefixed by an “@”1 as a decorator and apply it to the following function, class, or method definition. The compiler takes the completed definition and passes it as an argument to the decorator, and the decorator returns a function or class, which the original token (name) points to
@a_decorator
class Foo(object): "Foo" = a_decorator(class formerly-known-as Foo)
...
@a_decorator "Bar" = a_decorator(function fka Bar)
def Bar:
...
rab = Bar() rab is pointing to the result of
...