snakeoil.demandimport module

Import modules on demand.

See https://bugs.python.org/issue17621 for background.

snakeoil.demandimport.disable()[source]

Disable lazy loading for all future module imports.

snakeoil.demandimport.disabled()[source]

Context manager for temporarily disabling lazy imports.

Example usage: >>> from importlib.util import _LazyModule >>> from snakeoil import demandimport >>> demandimport.enable() >>> >>> with demandimport.disabled(): >>> from module import submodule >>> assert not isinstance(submodule, _LazyModule)

snakeoil.demandimport.enable()[source]

Enable lazy loading for all future module imports.

snakeoil.demandimport.enabled()[source]

Context manager for temporarily enabling lazy imports.

Useful as a workaround for avoiding circular import issues.

Example usage: >>> from importlib.util import _LazyModule >>> from snakeoil import demandimport >>> >>> with demandimport.enabled(): >>> from module import submodule >>> assert isinstance(submodule, _LazyModule) >>> from module2 import submodule2 >>> assert not isinstance(submodule2, _LazyModule)

snakeoil.demandimport.is_enabled()[source]

Determine if lazy loading is currently enabled.