diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2024-03-14 21:59:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-14 21:59:00 (GMT) |
commit | 5f52d20a93908196f74271db8437cc1ba7e1e262 (patch) | |
tree | 4e18f6819f86ebd9f1cfcdcf4211081fdae87ec9 | |
parent | be59aaf3abec37b27bdb31fadf433665e5471a46 (diff) | |
download | cpython-5f52d20a93908196f74271db8437cc1ba7e1e262.zip cpython-5f52d20a93908196f74271db8437cc1ba7e1e262.tar.gz cpython-5f52d20a93908196f74271db8437cc1ba7e1e262.tar.bz2 |
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
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 3 | ||||
-rw-r--r-- | Lib/importlib/metadata/__init__.py | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst | 2 |
3 files changed, 6 insertions, 0 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 46ddcee..b26be85 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -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'.""" diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index c612fbe..41c2a4a6 100644 --- a/Lib/importlib/metadata/__init__.py +++ b/Lib/importlib/metadata/__init__.py @@ -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() diff --git a/Misc/NEWS.d/next/Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst b/Misc/NEWS.d/next/Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst new file mode 100644 index 0000000..0016863 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst @@ -0,0 +1,2 @@ +In ``PathFinder.invalidate_caches``, delegate to +``MetadataPathFinder.invalidate_caches``. |