This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients ncoghlan
Date 2017-12-01.08:50:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512118241.83.0.213398074469.issue32192@psf.upfronthosting.co.za>
In-reply-to
Content
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"
History
Date User Action Args
2017-12-01 08:50:41ncoghlansetrecipients: + ncoghlan
2017-12-01 08:50:41ncoghlansetmessageid: <1512118241.83.0.213398074469.issue32192@psf.upfronthosting.co.za>
2017-12-01 08:50:41ncoghlanlinkissue32192 messages
2017-12-01 08:50:41ncoghlancreate