[3.11] gh-116811: Ensure MetadataPathFinder.invalidate_caches is reachable 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 5f52d20a93)
This commit is contained in:
Jason R. Coombs 2024-03-15 09:59:32 -04:00 committed by GitHub
parent eaefa0b1f7
commit 8acd6ca521
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View File

@ -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'."""

View File

@ -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()

View File

@ -0,0 +1,2 @@
In ``PathFinder.invalidate_caches``, delegate to
``MetadataPathFinder.invalidate_caches``.