Stacking Multiple Decorators
You can stack decorators - apply more than one to a function:
@decorator_a
@decorator_b
@decorator_c
def my_function():
pass
This is equivalent to:
my_function = decorator_a(decorator_b(decorator_c(my_function)))
Order matters! Decorators apply from bottom to top, but execute from top to bottom.
Example with logging and timing:
@timer
@logger
def process_data():
# ...
Here, logger wraps the original function first. Then timer wraps the logged version. When you call process_data(), timing runs first, then logging, then the actual function.
Think of it like layers of an onion - the outermost decorator is the first thing executed.
I explain decorator ordering in my Python Decorators course.