Decorators

Collection of meta-decorators to use on your decorators


Note:
All of the listed decorators are intended to be used only on decorators and decorator factories. Using them on regular functions will raise a custom TypeError by the library to avoid the misuse.
However, this detection is not fully type-safe due to python non typed nature even if the library try to enforce it. For details take a look at known limitations.

This should not pose a problem or have any real impact, as fooling the detection requires the developer to intentionally write misleading code.

@validate_decorated()

Signature

def validate_decorated(*validators: Callable[[Callable[..., Any], Any], Callable[..., Any]]) -> Callable[[Callable[..., Any]], Callable[..., Any]]

Description

For all provided validators, ensures that any function using the decorated decorator complies with those validators.

Parameters

  • *validators: Validator functions that check if the decorated function meets certain criteria

Raises

  • TypeError if used on a regular function or if a non-callable argument is provided.

Example use

@validate_decorated(require_params("x"), require_params("y"))
def my_decorator(func): return func

@my_decorator
def correct_usage(x, y): pass

@my_decorator
def bad_usage(x): pass # Will raise an DecoratorUsageValidationError