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 brett.cannon
Recipients Arfrever, aronacher, brett.cannon, eric.araujo, eric.snow, flox, ncoghlan, tshepang, yselivanov
Date 2014-05-26.14:49:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <[email protected]>
In-reply-to
Content
I think that's the wrong abstraction(it would be fine in a third-party library, though, that's trying to smooth over 3.3->3.4 transitions). Since importlib.util.find_spec() always returns a spec, then you want something more like::

  def load(spec):
    loader = spec.loader
    if hasattr(loader, 'exec_module'):
        module = importlib.util.whatever_issue_20383_leads_to()
        loader.exec_module(module)
        return module
    else:
        loader.load_module(spec.name)
        return sys.modules[spec.name]

Since this is Python 3.5 code we are talking about you don't have to worry about the find_loader/find_module case as find_spec wraps both of those and normalizes it all to just using specs. You could even tweak it to pass the module in explicitly and in the load_module branch make sure that the module is placed in sys.modules first so it essentially becomes a reload (but as both know that's not exactly the same nor pleasant in certain cases so probably best not exposed that way =).

If this exists in importlib.util then you make import_module() be (essentially)::

  def import_module(name, package):
    fullname = resolve_name(name, package)
    spec = find_spec(fullname)
    return load(spec)
History
Date User Action Args
2014-05-26 14:49:25brett.cannonsetrecipients: + brett.cannon, ncoghlan, aronacher, eric.araujo, Arfrever, flox, tshepang, eric.snow, yselivanov
2014-05-26 14:49:25brett.cannonsetmessageid: <[email protected]>
2014-05-26 14:49:25brett.cannonlinkissue21235 messages
2014-05-26 14:49:24brett.cannoncreate