This module contains various supporting functions that can be used independently of the Motor-ODM framework. Some of these utilities can be found in similar form in other packages or frameworks and are adapted here to reduce the number of dependencies.
inherit_class(name: str, self: Optional[T], *parents: T) → T¶
Performs a pseudo-inheritance by creating a new class that inherits from
parents. This is useful to support intuitive inheritance on inner classes (typically named
Note that this method neither returns
selfnor any of the
parentsbut a new type that inherits from both.
name – The name of the newly created type.
self – The primary base class (fields in this class take preference over the
parents – The secondary base classes. Field preferences are determined by the order of the parent classes.
A new type inheriting from
monkey_patch(cls: Union[type, module], name: Optional[str] = None) → Callable[[C], C]¶
Monkey patches class or module by adding to it decorated function. Anything overwritten can be accessed via a
.originalattribute of the decorated object.
cls – The class or module to be patched.
name – The name of the attribute to be patched.
A decorator that monkey patches
cls.nameand returns the decorated function.