[New-bugs-announce] [issue19944] Make importlib.find_spec load packages as needed

Nick Coghlan report at bugs.python.org
Tue Dec 10 13:29:01 CET 2013


New submission from Nick Coghlan:

In implementing the runpy module updates for PEP 451 I ran into the fact that importlib.find_spec had copied the find_loader behaviour where it doesn't handle dotted names automatically - you have to explicitly pass in the __path__ from the parent module for it to work.

For find_loader, runpy used pkgutil.get_loader instead. The patch on issue 19700 currently includes a runpy._fixed_find_spec function that handles walking the module name components, loading packages as necessary.

I believe it would be better to move the current thin wrapper around importlib._bootstrap._find_spec to importlib.find_spec_on_path (which will only search for the specified module name directly on the given path without breaking it up into components), with find_spec itself changed to *not* take a "path" argument, and instead always doing the full lookup (as implemented in the issue 19700 patch _fixed_find_spec function)

----------
components: Library (Lib)
messages: 205804
nosy: ncoghlan
priority: normal
severity: normal
status: open
title: Make importlib.find_spec load packages as needed
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19944>
_______________________________________


More information about the New-bugs-announce mailing list