summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-06-13 06:29:59 (GMT)
committerGitHub <noreply@github.com>2022-06-13 06:29:59 (GMT)
commit3d1c080591910c9c1ee80e5465ce7c91b67c907d (patch)
tree73ed1543305b638772713e4440565adf7b49baea /Lib/importlib
parent536af65e96490689c4d2eccc0afc3323f5763ff8 (diff)
downloadcpython-3d1c080591910c9c1ee80e5465ce7c91b67c907d.zip
cpython-3d1c080591910c9c1ee80e5465ce7c91b67c907d.tar.gz
cpython-3d1c080591910c9c1ee80e5465ce7c91b67c907d.tar.bz2
gh-93461: Invalidate sys.path_importer_cache entries with relative paths (GH-93653)
(cherry picked from commit 09243b898a13f3f61e275c1031143d1225e70916) Co-authored-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap_external.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 5f67226..0061ad0 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -1394,7 +1394,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()
@@ -1562,9 +1564,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()