From e8b6d1e508004ec554323ec21b0746aa8f5a488c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 14 Mar 2024 09:56:51 -0400 Subject: [PATCH 1/3] Make MetadataPathFinder a proper classmethod. --- Lib/importlib/metadata/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index c612fbefee2e80..41c2a4a6088b5d 100644 --- a/Lib/importlib/metadata/__init__.py +++ b/Lib/importlib/metadata/__init__.py @@ -797,6 +797,7 @@ def _search_paths(cls, name, paths): path.search(prepared) for path in map(FastPath, paths) ) + @classmethod def invalidate_caches(cls) -> None: FastPath.__new__.cache_clear() From 9fad4615fa05e0f68ccf3b79316f67c05e090ce8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 13 Mar 2024 14:59:17 -0400 Subject: [PATCH 2/3] In PathFinder.invalidate_caches, also invoke MetadataPathFinder.invalidate_caches. --- Lib/importlib/_bootstrap_external.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 46ddceed07b0d4..b26be8583d0f81 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1470,6 +1470,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'.""" From 2030b1cb409d6c158b69ed82d2ae1908e1559263 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 14 Mar 2024 10:01:29 -0400 Subject: [PATCH 3/3] Add blurb --- .../next/Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-03-14-10-01-23.gh-issue-116811._h5iKP.rst 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``.