Message307370
While importlib provides all the *pieces* to implement lazy imports, we don't actually provide a clear way of chaining them together into a lazy import operation. Without any error checking, that looks like:
import sys
import importlib.util
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.TYPE_CHECKING
False
I'm thinking it may make sense to just provide a robust implementation of that, and accept that it may lead to some bug reports that are closed with "You need to fix the module you're loading to be compatible with lazy imports" |
|
Date |
User |
Action |
Args |
2017-12-01 08:50:41 | ncoghlan | set | recipients:
+ ncoghlan |
2017-12-01 08:50:41 | ncoghlan | set | messageid: <1512118241.83.0.213398074469.issue32192@psf.upfronthosting.co.za> |
2017-12-01 08:50:41 | ncoghlan | link | issue32192 messages |
2017-12-01 08:50:41 | ncoghlan | create | |
|