Skip to content

Method

Method markers are used to attach a metadata that is relevant to a whole request rather than a specific parameter.

Examples:

Since there's no «native» way to mark a function in Python, the method markers are usually decorators that doesn't change a behaviour of a wrapped function.

Core markers

Contrary to the support markers, the core markers are independent of application protocols or backends:

wrap_with

wrap_with(decorator: Callable[[Any], Any]) -> Callable[[FunctionT], FunctionT]

Wrap the generated bound service method with decorator.

Examples:

>>> @wrap_with(functools.cache)
>>> def service_method(self, ...) -> ...:
>>>     ...
Why can I not just use a decorator directly?

The decorator needs to wrap a method implementation and a service definition is just an interface. If you put it directly onto an abstract method, it would wrap only this abstract method, but not the actual implementation which is produced by binding.

Source code in combadge/core/markers/method.py
def wrap_with(decorator: Callable[[Any], Any]) -> Callable[[FunctionT], FunctionT]:
    """
    Wrap the generated bound service method with decorator.

    Examples:
        >>> @wrap_with(functools.cache)
        >>> def service_method(self, ...) -> ...:
        >>>     ...

    Question: Why can I not just use a decorator directly?
        The decorator needs to wrap a method **implementation** and a service definition is just an **interface**.
        If you put it directly onto an abstract method, it would wrap only this abstract method,
        but **not** the actual implementation which is produced by [binding][binding].
    """
    return WrapWith(decorator).mark