Managing Calls and Instances
For example, in typical use, this automatically run code may be used to augment calls to functions and classes. It arranges this by installing wrapper objects to be invoked later:
- Function decorators install wrapper objects to intercept later function calls and process them as needed.
- Class decorators install wrapper objects to intercept later instance creation calls and process them as required.
Decorators achieve these effects by automatically rebinding function and class names to other callables, at the end of def and class statements. When later invoked, these callables can perform tasks such as tracing and timing function calls, managing access to class instance attributes, and so on.