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.

classification
Title: pkgutil.get_importer only return the first valid path_hook(importer)
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Windson Yang, christian.heimes
Priority: normal Keywords: patch

Created on 2019-03-28 00:11 by Windson Yang, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 19921 open christian.heimes, 2020-05-05 11:54
Messages (3)
msg339000 - (view) Author: Windson Yang (Windson Yang) * Date: 2019-03-28 00:11
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.
msg339057 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-03-28 16:41
To clarify, this is for pkgutil.
msg365141 - (view) Author: Windson Yang (Windson Yang) * Date: 2020-03-27 09:07
Any update?
History
Date User Action Args
2022-04-11 14:59:13adminsetgithub: 80634
2020-05-05 11:54:37christian.heimessetkeywords: + patch
nosy: + christian.heimes

pull_requests: + pull_request19236
stage: patch review
2020-03-27 09:07:28Windson Yangsetmessages: + msg365141
2019-03-28 16:41:20brett.cannonsetnosy: - brett.cannon
2019-03-28 16:41:07brett.cannonsetnosy: + brett.cannon
messages: + msg339057
2019-03-28 16:40:54brett.cannonsettitle: get_importer only return the first valid path_hook(importer) -> pkgutil.get_importer only return the first valid path_hook(importer)
2019-03-28 00:11:08Windson Yangcreate