Module motor_odm.helpers
¶
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.
-
motor_odm.helpers.
inherit_class
(name: str, self: Optional[T], *parents: T) → T¶ Performs a pseudo-inheritance by creating a new class that inherits from
self
andparents
. This is useful to support intuitive inheritance on inner classes (typically namedMeta
).Note that this method neither returns
self
nor any of theparents
but a new type that inherits from both.- Parameters
name – The name of the newly created type.
self – The primary base class (fields in this class take preference over the
parents
’ fields.parents – The secondary base classes. Field preferences are determined by the order of the parent classes.
- Returns
A new type inheriting from
self
andparents
.
-
motor_odm.helpers.
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
.original
attribute of the decorated object.- Parameters
cls – The class or module to be patched.
name – The name of the attribute to be patched.
- Returns
A decorator that monkey patches
cls.name
and returns the decorated function.