Skip to main content

recreate_module

Replaces an existing module in sys.modules with a new LazyModule instance, mapping compatibility modules and object origins while preserving the original module's specification.

def recreate_module(
name: string,
compat_modules: list,
by_module: dict,
direct: dict,
base: class,
**attrs: any
) - > tuple

Replaces an existing module in sys.modules with a LazyModule instance to support lazy loading of sub-modules and attributes.

Parameters

NameTypeDescription
namestringThe fully qualified name of the module to be recreated.
compat_moduleslistA list of compatibility module names to be integrated into the new module's namespace.
by_moduledictA mapping of module paths to the attributes they export, used to resolve lazy imports.
directdictA dictionary of attributes to be mapped directly to the new module.
baseclassThe base class used to instantiate the new module, defaulting to LazyModule.
**attrsanyAdditional keyword arguments to be set as attributes on the new module.

Returns

TypeDescription
tupleA tuple containing the original module object and the newly created lazy module instance.