diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-09 19:23:58 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-09 19:23:58 (GMT) |
commit | b2dd880e0a9e9936de92a508bcff28e253a04c8e (patch) | |
tree | 53581a495dac07d0a085738ca6a7ec86511d3fb0 /Lib/pkgutil.py | |
parent | 7df5e5858b846b9de6dd1148d13e105712c8b1e1 (diff) | |
download | cpython-b2dd880e0a9e9936de92a508bcff28e253a04c8e.zip cpython-b2dd880e0a9e9936de92a508bcff28e253a04c8e.tar.gz cpython-b2dd880e0a9e9936de92a508bcff28e253a04c8e.tar.bz2 |
Issue #15294: Fix a regression in pkgutil.extend_path()'s handling of nested namespace packages.
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r-- | Lib/pkgutil.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py index c5b0c4d..59c99bf 100644 --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -513,12 +513,22 @@ def extend_path(path, name): # frozen package. Return the path unchanged in that case. return path - pname = os.path.join(*name.split('.')) # Reconstitute as relative path sname_pkg = name + ".pkg" path = path[:] # Start with a copy of the existing path - for dir in sys.path: + parent_package, _, final_name = name.rpartition('.') + if parent_package: + try: + search_path = sys.modules[parent_package].__path__ + except (KeyError, AttributeError): + # We can't do anything: find_loader() returns None when + # passed a dotted name. + return path + else: + search_path = sys.path + + for dir in search_path: if not isinstance(dir, str): continue @@ -526,7 +536,7 @@ def extend_path(path, name): if finder is not None: # Is this finder PEP 420 compliant? if hasattr(finder, 'find_loader'): - loader, portions = finder.find_loader(name) + loader, portions = finder.find_loader(final_name) else: # No, no need to call it loader = None |