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
This commit is contained in:
Jason R. Coombs 2024-03-14 17:59:00 -04:00 committed by GitHub
parent be59aaf3ab
commit 5f52d20a93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View File

@ -1470,6 +1470,9 @@ class PathFinder:
# 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

@ -797,6 +797,7 @@ class MetadataPathFinder(DistributionFinder):
path.search(prepared) for path in map(FastPath, paths)
)
@classmethod
def invalidate_caches(cls) -> None:
FastPath.__new__.cache_clear()

View File

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