diff options
author | Christian Heimes <christian@python.org> | 2022-06-10 23:56:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-10 23:56:26 +0200 |
commit | 09243b898a13f3f61e275c1031143d1225e70916 (patch) | |
tree | fe8d33df19d464585d2f4391c262b225834f3f28 /Lib/importlib/_bootstrap_external.py | |
parent | cf730b595eea0460a7305205f7dfb6ecf0346351 (diff) | |
download | cpython-09243b898a13f3f61e275c1031143d1225e70916.tar.gz cpython-09243b898a13f3f61e275c1031143d1225e70916.zip |
gh-93461: Invalidate sys.path_importer_cache entries with relative paths (GH-93653)
Diffstat (limited to 'Lib/importlib/_bootstrap_external.py')
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 1b6654202f3..8605c2a037d 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1399,7 +1399,9 @@ class PathFinder: """Call the invalidate_caches() method on all path entry finders stored in sys.path_importer_caches (where implemented).""" for name, finder in list(sys.path_importer_cache.items()): - if finder is None: + # Drop entry if finder name is a relative path. The current + # working directory may have changed. + if finder is None or not _path_isabs(name): del sys.path_importer_cache[name] elif hasattr(finder, 'invalidate_caches'): finder.invalidate_caches() @@ -1567,9 +1569,12 @@ class FileFinder: loaders.extend((suffix, loader) for suffix in suffixes) self._loaders = loaders # Base (directory) path - self.path = path or '.' - if not _path_isabs(self.path): - self.path = _path_join(_os.getcwd(), self.path) + if not path or path == '.': + self.path = _os.getcwd() + elif not _path_isabs(path): + self.path = _path_join(_os.getcwd(), path) + else: + self.path = path self._path_mtime = -1 self._path_cache = set() self._relaxed_path_cache = set() |