A bit more general:
def composed(*decs):
def deco(f):
for dec in reversed(decs):
f = dec(f)
return f
return deco
Then
@composed(dec1, dec2)
def some(f):
pass
is equivalent to
@dec1
@dec2
def some(f):
pass
More Related Contents:
- How to make function decorators and chain them together?
- Creating a singleton in Python
- Decorators with parameters?
- What does functools.wraps do?
- Preserving signatures of decorated functions
- How to decorate a class?
- How to decorate all functions of a class without typing it over and over for each method? [duplicate]
- How can I separate the functions of a class into multiple files?
- Attaching a decorator to all functions within a class
- How to strip decorators from a function in Python
- Decorator execution order
- Can a decorator of an instance method access the class?
- How to create a decorator that can be used either with or without parameters?
- Python decorator handling docstrings
- How to inject variable into scope with a decorator?
- How to decorate a method inside a class?
- Python Class Based Decorator with parameters that can decorate a method or a function
- What is the best way to do automatic attribute assignment in Python, and is it a good idea?
- How do I make function decorators and chain them together?
- How to make function decorators and chain them together in Python?
- How to create abstract properties in python abstract classes
- How to get all methods of a Python class with given decorator?
- How to do a conditional decorator in python?
- How can I pass a variable in a decorator to function’s argument in a decorated function?
- How do I write a decorator that restores the cwd?
- Using python decorator with or without parentheses
- How to create a custom decorator in Django?
- Currying decorator in python
- Python decorator best practice, using a class vs a function
- Applying a decorator to every method in a class?