snakeoil.demandimport module¶
Import modules on demand.
See https://bugs.python.org/issue17621 for background.
- 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.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)