Skip to content

Commit 983288b

Browse files
committed
gh-93461: Invalidate sys.path_importer_cache entries with relative paths
1 parent 30610d2 commit 983288b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Lib/importlib/_bootstrap_external.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,9 @@ def invalidate_caches():
13991399
"""Call the invalidate_caches() method on all path entry finders
14001400
stored in sys.path_importer_caches (where implemented)."""
14011401
for name, finder in list(sys.path_importer_cache.items()):
1402-
if finder is None:
1402+
# Drop entry if finder name is a relative path. The current
1403+
# working directory may have changed.
1404+
if finder is None or not _path_isabs(name):
14031405
del sys.path_importer_cache[name]
14041406
elif hasattr(finder, 'invalidate_caches'):
14051407
finder.invalidate_caches()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:func:`importlib.invalidate_caches` now drops entries from
2+
:data:`sys.path_importer_cache` with a relative path as name. This solves a
3+
caching issue when a process changes its current working directory.

0 commit comments

Comments
 (0)