Skip to content

Commit

Permalink
[3.11] gh-116811: Ensure MetadataPathFinder.invalidate_caches is reac…
Browse files Browse the repository at this point in the history
…hable when delegated through PathFinder. (GH-116812) (#116865)

* Make MetadataPathFinder a proper classmethod.

* In PathFinder.invalidate_caches, also invoke MetadataPathFinder.invalidate_caches.

* Add blurb
(cherry picked from commit 5f52d20)
  • Loading branch information
jaraco authored Mar 15, 2024
1 parent eaefa0b commit 8acd6ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,9 @@ def invalidate_caches():
# https://bugs.python.org/issue45703
_NamespacePath._epoch += 1

from importlib.metadata import MetadataPathFinder
MetadataPathFinder.invalidate_caches()

@staticmethod
def _path_hooks(path):
"""Search sys.path_hooks for a finder for 'path'."""
Expand Down
1 change: 1 addition & 0 deletions Lib/importlib/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ def _search_paths(cls, name, paths):
path.search(prepared) for path in map(FastPath, paths)
)

@classmethod
def invalidate_caches(cls):
FastPath.__new__.cache_clear()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In ``PathFinder.invalidate_caches``, delegate to
``MetadataPathFinder.invalidate_caches``.

0 comments on commit 8acd6ca

Please sign in to comment.