[New-bugs-announce] [issue36453] get_importer only return the first valid path_hook(importer)

Windson Yang report at bugs.python.org
Wed Mar 27 20:11:08 EDT 2019


New submission from Windson Yang <wiwindson at outlook.com>:

Is it an expected behavior the get_importer function only returns the first valid path_hook(importer) from sys.path_hooks?

def get_importer(path_item):
    """Retrieve a finder for the given path item

    The returned finder is cached in sys.path_importer_cache
    if it was newly created by a path hook.

    The cache (or part of it) can be cleared manually if a
    rescan of sys.path_hooks is necessary.
    """
    try:
        importer = sys.path_importer_cache[path_item]
    except KeyError:
        for path_hook in sys.path_hooks:
            try:
                importer = path_hook(path_item)
                sys.path_importer_cache.setdefault(path_item, importer)
                break
            except ImportError:
                pass
        else:
            importer = None
    return importer

Does the order in sys.path_hooks matters? We should document it if it does. Btw get_importer function is lack of test.

----------
components: Library (Lib)
messages: 339000
nosy: Windson Yang
priority: normal
severity: normal
status: open
title: get_importer only return the first valid path_hook(importer)
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36453>
_______________________________________


More information about the New-bugs-announce mailing list