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 and parents. This is useful to support intuitive inheritance on inner classes (typically named Meta).

Note that this method neither returns self nor any of the parents but 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’ fields.

  • parents – The secondary base classes. Field preferences are determined by the order of the parent classes.


A new type inheriting from self and parents.

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.

  • cls – The class or module to be patched.

  • name – The name of the attribute to be patched.


A decorator that monkey patches and returns the decorated function.