You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide importlib.util.lazy_import helper function #76373
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:
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"
Activity
ncoghlan commentedon Dec 1, 2017
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:
>>> lazy_typing = lazy_import("typing") >>> lazy_typing.TYPE_CHECKING FalseI'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"
brettcannon commentedon Dec 1, 2017
Already planning this as a PyPI package (at least to start). See https://notebooks.azure.com/Brett/libraries/di2Btqj7zSI/html/Lazy%20importing.ipynb for the design.
ncoghlan commentedon Dec 3, 2017
Maintaining the actual implementation as a third party module seems like a good idea to me, so I'm marking this as a documentation issue instead.
The idea would be to add this as an example of a very basic lazy importer under https://docs.python.org/3/library/importlib.html#examples
nanjekyejoannah commentedon Jul 13, 2020
New changeset 8dd32fe by Joannah Nanjekye in branch 'master':
bpo-32192: A basic lazy importer example (GH-21330)
8dd32fe
iritkatriel commentedon Oct 3, 2020
This seems complete. Can is be closed?
brettcannon commentedon Oct 5, 2020
Yep, I think the example is enough to close this. Thanks!