Bound method wrapper
BoundMethodWrapper
Bases: Generic[TOwner, TParams, TConfig]
Async method wrapper that also acts as a bound instance method when it replaces an instance method of a class.
Note: the wrapped method will be unbound.
Caveats
This class acts as if it was a bound method of the instance using the descriptor protocol, but of course it is not a bound method, which becomes important when trying to apply decorators on the wrapper instance. In those cases the wrapper acts as a static method whose first argument is the instance, so you need to apply decorators that match this signature.
Configuration
exception: An optional exception factory (or type) that accepts a single string
argument and returns an exception. If not None, then exceptions
raised by the wrapped method will be caught and replaced by the exception
this method produces.
Source code in fastapi_motor_oil/bound_method_wrapper.py
config: TConfig
property
Wrapper configuration.
name: str
property
The (qualified) name of the wrapped method.
__call__(owner, *args, **kwargs)
async
Executes the wrapped unbound method with the given owner.
Exceptions raised by the wrapped method will be transformed by the exception attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner |
TOwner
|
The owner instance of the wrapper (the |
required |
*args |
TParams.args
|
The wrapped method's positional arguments. |
()
|
*kwargs |
TParams.kwargs
|
The wrapped method's keyword arguments. |
{}
|
Source code in fastapi_motor_oil/bound_method_wrapper.py
__get__(owner, obj_type=None)
Descriptor implementation that makes the wrapper work as a bound method of its owner.
Source code in fastapi_motor_oil/bound_method_wrapper.py
__init__(func, config)
Initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func |
Callable[Concatenate[TOwner, TParams], Coroutine[None, None, None]]
|
The wrapped method. |
required |
config |
TConfig
|
Wrapper configuration. |
required |