From 8336cb2b6f428246803b02a4e97fce49d0bb1e09 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 15 Mar 2024 09:59:28 -0400 Subject: [PATCH] [3.12] gh-116811: Ensure MetadataPathFinder.invalidate_caches is reachable when delegated through PathFinder. (GH-116812) (#116864) * Make MetadataPathFinder a proper classmethod. * In PathFinder.invalidate_caches, also invoke MetadataPathFinder.invalidate_caches. * Add blurb (cherry picked from commit 5f52d20a93908196f74271db8437cc1ba7e1e262) --- Lib/importlib/_bootstrap_external.py | 3 +++ Lib/importlib/metadata/__init__.py | 1 + .../Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index e6f75a9f6f63d4..61dafc0f4cb953 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1450,6 +1450,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'.""" diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index 82e0ce1b281c54..54156e93afc5d4 100644 --- a/Lib/importlib/metadata/__init__.py +++ b/Lib/importlib/metadata/__init__.py @@ -795,6 +795,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() 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 00000000000000..00168632429996 --- /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``.