Visitar URL original
gh-93461: Invalidate sys.path_importer_cache entries with relative paths by tiran · Pull Request #93653 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-93461: Invalidate sys.path_importer_cache entries with relative paths
  • Loading branch information
tiran committed Jun 9, 2022
commit 983288bdfb0aa6f4f0cc81d4bf9d5b726e2e5a61
4 changes: 3 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,9 @@ def invalidate_caches():
"""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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`importlib.invalidate_caches` now drops entries from
:data:`sys.path_importer_cache` with a relative path as name. This solves a
caching issue when a process changes its current working directory.