Skip to content

Commit 5f52d20

Browse files
authored
gh-116811: Ensure MetadataPathFinder.invalidate_caches is reachable when delegated through PathFinder. (#116812)
* Make MetadataPathFinder a proper classmethod. * In PathFinder.invalidate_caches, also invoke MetadataPathFinder.invalidate_caches. * Add blurb
1 parent be59aaf commit 5f52d20

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

Lib/importlib/_bootstrap_external.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,9 @@ def invalidate_caches():
14701470
# https://bugs.python.org/issue45703
14711471
_NamespacePath._epoch += 1
14721472

1473+
from importlib.metadata import MetadataPathFinder
1474+
MetadataPathFinder.invalidate_caches()
1475+
14731476
@staticmethod
14741477
def _path_hooks(path):
14751478
"""Search sys.path_hooks for a finder for 'path'."""

Lib/importlib/metadata/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ def _search_paths(cls, name, paths):
797797
path.search(prepared) for path in map(FastPath, paths)
798798
)
799799

800+
@classmethod
800801
def invalidate_caches(cls) -> None:
801802
FastPath.__new__.cache_clear()
802803

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In ``PathFinder.invalidate_caches``, delegate to
2+
``MetadataPathFinder.invalidate_caches``.

0 commit comments

Comments
 (0)