PyDocs

Nav

Importing Modules

LazyLoader

importlib.util

class · Added in 3.5 (source)
  • LazyLoader(loader)
A loader that creates a module which defers loading until attribute access.
Changed in 3.6
  • 3.6: Began calling create_module(), removing the compatibility warning for importlib.machinery.BuiltinImporter and importlib.machinery.ExtensionFileLoader.
Members of LazyLoader

f

factory
Construct a callable which returns the eager loader made lazy.
1 Example
>>> import importlib.util
>>> import sys
>>> def lazy_import(name):
...     spec = importlib.util.find_spec(name)
...     loader = importlib.util.LazyLoader(spec.loader)
...     spec.loader = loader
...     module = importlib.util.module_from_spec(spec)
...     sys.modules[name] = module
...     loader.exec_module(module)
...     return module
...
>>> lazy_typing = lazy_import("typing")
>>> #lazy_typing is a real module object,
>>> #but it is not loaded in memory yet.
>>> lazy_typing.TYPE_CHECKING
False
from the Python docs
See Also
No see-alsos for importlib.util/LazyLoader
0 Notes
No notes for LazyLoader