From d4844c54419a69f417144d4bfe0aeb9787b9cea3 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sun, 15 Dec 2024 17:52:30 +0100 Subject: [PATCH 01/14] Add DeprecationWarning for path_mtime Co-authored-by: rashansmith --- Lib/importlib/abc.py | 5 +++++ Lib/test/test_importlib/test_abc.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index eea6b38af6fa13..30b5c5b3e0ca3f 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -199,6 +199,11 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo def path_mtime(self, path): """Return the (int) modification time for the path (str).""" + import warnings + warnings.warn("SourceLoader.path_mtime is deprecated in favour of " + "SourceLoader.path_stats().", + DeprecationWarning, + stacklevel=2) if self.path_stats.__func__ is SourceLoader.path_stats: raise OSError return int(self.path_stats(path)['mtime']) diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py index 603125f6d926f6..3cc8c0611a74d7 100644 --- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -913,5 +913,25 @@ def test_universal_newlines(self): SourceOnlyLoaderMock=SPLIT_SOL) +class SourceLoaderDeprecationWarningsTests(unittest.TestCase): + """Tests SourceLoader deprecation warnings.""" + + def test_deprecated_path_mtime(self): + from importlib.abc import SourceLoader + class DummySourceLoader(SourceLoader): + def get_data(self, path): + return b'' + + def get_filename(self, fullname): + return 'foo.py' + + def path_stats(self, path): + return {'mtime': 1} + + loader = DummySourceLoader() + with self.assertWarns(DeprecationWarning): + loader.path_mtime('foo.py') + + if __name__ == '__main__': unittest.main() From cbe54a3f11dcecaab87eddb80841181c32523a5a Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sun, 15 Dec 2024 18:22:13 +0100 Subject: [PATCH 02/14] Add DeprecationWarning for ResourceLoader Co-authored-by: rashansmith --- Lib/importlib/abc.py | 9 +++++++++ Lib/test/test_importlib/test_abc.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index 30b5c5b3e0ca3f..8cbd544a140a94 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -70,6 +70,15 @@ class ResourceLoader(Loader): """ + def __init__(self): + import warnings + warnings.warn("importlib.abc.ResourceLoader is deprecated in " + "favour of supporting resource loading through " + "importlib.resources.abc.ResourceReader.", + DeprecationWarning, stacklevel=2) + super().__init__() + + @abc.abstractmethod def get_data(self, path): """Abstract method which when implemented should return the bytes for diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py index 3cc8c0611a74d7..83e9ca3b3e3976 100644 --- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -933,5 +933,13 @@ def path_stats(self, path): loader.path_mtime('foo.py') +class ResourceLoaderDeprecationWarningsTests(unittest.TestCase): + """Tests ResourceLoader deprecation warnings.""" + + def test_deprecated_resource_loader(self): + with self.assertWarns(DeprecationWarning): + from importlib.abc import ResourceLoader + + if __name__ == '__main__': unittest.main() From b73ad858e8589db88cee3fa142f60da192088dc2 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sun, 15 Dec 2024 18:36:17 +0100 Subject: [PATCH 03/14] Add DeprecationWarning for DEBUG_BYTECODE_SUFFIXES and OPTIMIZED_BYTECODE_SUFFIXES. Co-authored-by: rashansmith --- Lib/importlib/machinery.py | 26 +++++++++++++++++++++++--- Lib/test/test_importlib/test_api.py | 9 +++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py index 6e294d59bfdcb9..789c5d600b6323 100644 --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -3,9 +3,11 @@ from ._bootstrap import ModuleSpec from ._bootstrap import BuiltinImporter from ._bootstrap import FrozenImporter -from ._bootstrap_external import (SOURCE_SUFFIXES, DEBUG_BYTECODE_SUFFIXES, - OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES, - EXTENSION_SUFFIXES) +from ._bootstrap_external import ( + SOURCE_SUFFIXES, BYTECODE_SUFFIXES, EXTENSION_SUFFIXES, + DEBUG_BYTECODE_SUFFIXES as _DEBUG_BYTECODE_SUFFIXES, + OPTIMIZED_BYTECODE_SUFFIXES as _OPTIMIZED_BYTECODE_SUFFIXES +) from ._bootstrap_external import WindowsRegistryFinder from ._bootstrap_external import PathFinder from ._bootstrap_external import FileFinder @@ -27,3 +29,21 @@ def all_suffixes(): 'NamespaceLoader', 'OPTIMIZED_BYTECODE_SUFFIXES', 'PathFinder', 'SOURCE_SUFFIXES', 'SourceFileLoader', 'SourcelessFileLoader', 'WindowsRegistryFinder', 'all_suffixes'] + + +def __getattr__(name): + import warnings + if name == 'DEBUG_BYTECODE_SUFFIXES': + warnings.warn("importlib.machinery.DEBUG_BYTECODE_SUFFIXES is " + "deprecated. Use importlib.machinery.BYTECODE_SUFFIXES " + "instead.", + DeprecationWarning, stacklevel=2) + return _DEBUG_BYTECODE_SUFFIXES + elif name == 'OPTIMIZED_BYTECODE_SUFFIXES': + warnings.warn("importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES is " + "deprecated. Use importlib.machinery.BYTECODE_SUFFIXES " + "instead.", + DeprecationWarning, stacklevel=2) + return _OPTIMIZED_BYTECODE_SUFFIXES + + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index 51ea5270b1a928..c95ab24d70aa09 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -492,5 +492,14 @@ def test_util(self): support.check__all__(self, util['Source'], extra=extra) +class TestDeprecations(unittest.TestCase): + def test_machinery_deprecated_constants(self): + from importlib import machinery + for attr in ('DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES'): + with self.subTest(attr=attr): + with self.assertWarns(DeprecationWarning): + getattr(machinery, attr) + + if __name__ == '__main__': unittest.main() From 5375cf6be019e038b10355d596eb300f69694d01 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sun, 15 Dec 2024 20:34:07 +0100 Subject: [PATCH 04/14] Add DeprecationWarning for WindowsRegistryFinder Co-authored-by: rashansmith --- Lib/importlib/_bootstrap_external.py | 8 ++++++++ Lib/importlib/machinery.py | 1 + Lib/test/test_importlib/test_api.py | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index fa36159711846f..62ae1ee2081f6d 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -692,6 +692,14 @@ class WindowsRegistryFinder: '\\Modules\\{fullname}\\Debug') DEBUG_BUILD = (_MS_WINDOWS and '_d.pyd' in EXTENSION_SUFFIXES) + def __init__(self): + import warnings + warnings.warn("importlib.machinery.WindowsRegistryFinder is " + "deprecated. Use site configuration instead. " + "Future versions of Python may not enable this " + "finder by default.", + DeprecationWarning, stacklevel=2) + @staticmethod def _open_registry(key): try: diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py index 789c5d600b6323..a9e6abba67c890 100644 --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -33,6 +33,7 @@ def all_suffixes(): def __getattr__(name): import warnings + if name == 'DEBUG_BYTECODE_SUFFIXES': warnings.warn("importlib.machinery.DEBUG_BYTECODE_SUFFIXES is " "deprecated. Use importlib.machinery.BYTECODE_SUFFIXES " diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index c95ab24d70aa09..e938161003559f 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -493,9 +493,14 @@ def test_util(self): class TestDeprecations(unittest.TestCase): - def test_machinery_deprecated_constants(self): + def test_machinery_deprecated_members(self): from importlib import machinery - for attr in ('DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES'): + attributes = ( + 'DEBUG_BYTECODE_SUFFIXES', + 'OPTIMIZED_BYTECODE_SUFFIXES', + 'WindowsRegistryFinder', + ) + for attr in attributes: with self.subTest(attr=attr): with self.assertWarns(DeprecationWarning): getattr(machinery, attr) From 3306e7e5c9cddd40f682031d42052272361e1b1b Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Mon, 16 Dec 2024 21:46:47 +0100 Subject: [PATCH 05/14] Update tests --- Lib/test/test_importlib/test_abc.py | 8 ++++++-- Lib/test/test_importlib/test_api.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py index 83e9ca3b3e3976..00af2dd712425a 100644 --- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -937,9 +937,13 @@ class ResourceLoaderDeprecationWarningsTests(unittest.TestCase): """Tests ResourceLoader deprecation warnings.""" def test_deprecated_resource_loader(self): - with self.assertWarns(DeprecationWarning): - from importlib.abc import ResourceLoader + from importlib.abc import ResourceLoader + class DummyLoader(ResourceLoader): + def get_data(self, path): + return b'' + with self.assertWarns(DeprecationWarning): + DummyLoader() if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index e938161003559f..20308d2e6e0b57 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -493,18 +493,22 @@ def test_util(self): class TestDeprecations(unittest.TestCase): - def test_machinery_deprecated_members(self): + def test_machinery_deprecated_attributes(self): from importlib import machinery attributes = ( 'DEBUG_BYTECODE_SUFFIXES', 'OPTIMIZED_BYTECODE_SUFFIXES', - 'WindowsRegistryFinder', ) for attr in attributes: with self.subTest(attr=attr): with self.assertWarns(DeprecationWarning): getattr(machinery, attr) + def test_deprecated_windows_registry_finder(self): + from importlib.machinery import WindowsRegistryFinder + with self.assertWarns(DeprecationWarning): + WindowsRegistryFinder() + if __name__ == '__main__': unittest.main() From 5c7c5e9c24e77d8000d9aa854874c53509762595 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Mon, 16 Dec 2024 22:20:44 +0100 Subject: [PATCH 06/14] Add news entry --- .../next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst diff --git a/Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst b/Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst new file mode 100644 index 00000000000000..1f4449b475482a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst @@ -0,0 +1 @@ +Add missing Deprecation warnings for several :mod:`importlib` members. From 7079bddfccd54ba3a1f87b6e633189ae0a63d618 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Mon, 16 Dec 2024 22:24:49 +0100 Subject: [PATCH 07/14] Unify quotes --- Lib/importlib/_bootstrap_external.py | 8 ++++---- Lib/importlib/abc.py | 10 +++++----- Lib/importlib/machinery.py | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 62ae1ee2081f6d..5cca5177d3224d 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -694,10 +694,10 @@ class WindowsRegistryFinder: def __init__(self): import warnings - warnings.warn("importlib.machinery.WindowsRegistryFinder is " - "deprecated. Use site configuration instead. " - "Future versions of Python may not enable this " - "finder by default.", + warnings.warn('importlib.machinery.WindowsRegistryFinder is ' + 'deprecated. Use site configuration instead. ' + 'Future versions of Python may not enable this ' + 'finder by default.', DeprecationWarning, stacklevel=2) @staticmethod diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index 8cbd544a140a94..cc4fcd1e146673 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -72,9 +72,9 @@ class ResourceLoader(Loader): def __init__(self): import warnings - warnings.warn("importlib.abc.ResourceLoader is deprecated in " - "favour of supporting resource loading through " - "importlib.resources.abc.ResourceReader.", + warnings.warn('importlib.abc.ResourceLoader is deprecated in ' + 'favour of supporting resource loading through ' + 'importlib.resources.abc.ResourceReader.', DeprecationWarning, stacklevel=2) super().__init__() @@ -209,8 +209,8 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo def path_mtime(self, path): """Return the (int) modification time for the path (str).""" import warnings - warnings.warn("SourceLoader.path_mtime is deprecated in favour of " - "SourceLoader.path_stats().", + warnings.warn('SourceLoader.path_mtime is deprecated in favour of ' + 'SourceLoader.path_stats().', DeprecationWarning, stacklevel=2) if self.path_stats.__func__ is SourceLoader.path_stats: diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py index a9e6abba67c890..7e71f5035d0ae5 100644 --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -35,16 +35,16 @@ def __getattr__(name): import warnings if name == 'DEBUG_BYTECODE_SUFFIXES': - warnings.warn("importlib.machinery.DEBUG_BYTECODE_SUFFIXES is " - "deprecated. Use importlib.machinery.BYTECODE_SUFFIXES " - "instead.", + warnings.warn('importlib.machinery.DEBUG_BYTECODE_SUFFIXES is ' + 'deprecated. Use importlib.machinery.BYTECODE_SUFFIXES ' + 'instead.', DeprecationWarning, stacklevel=2) return _DEBUG_BYTECODE_SUFFIXES elif name == 'OPTIMIZED_BYTECODE_SUFFIXES': - warnings.warn("importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES is " - "deprecated. Use importlib.machinery.BYTECODE_SUFFIXES " - "instead.", + warnings.warn('importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES is ' + 'deprecated. Use importlib.machinery.BYTECODE_SUFFIXES ' + 'instead.', DeprecationWarning, stacklevel=2) return _OPTIMIZED_BYTECODE_SUFFIXES - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + raise AttributeError(f'module {__name__!r} has no attribute {name!r}') From 651e40ecb01587cd5bdaf63921aa0736ea634756 Mon Sep 17 00:00:00 2001 From: "Tomas R." Date: Mon, 16 Dec 2024 22:55:15 +0100 Subject: [PATCH 08/14] Update Lib/importlib/abc.py Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Lib/importlib/abc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index cc4fcd1e146673..bb2837d38d83f1 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -211,8 +211,7 @@ def path_mtime(self, path): import warnings warnings.warn('SourceLoader.path_mtime is deprecated in favour of ' 'SourceLoader.path_stats().', - DeprecationWarning, - stacklevel=2) + DeprecationWarning, stacklevel=2) if self.path_stats.__func__ is SourceLoader.path_stats: raise OSError return int(self.path_stats(path)['mtime']) From df86fcff3df8367c074f18c43adb99f710dcc247 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Mon, 16 Dec 2024 22:58:45 +0100 Subject: [PATCH 09/14] Fix tests --- Lib/inspect.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index b7d8271f8a471f..74f0194f2b47e4 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -857,8 +857,7 @@ def getsourcefile(object): Return None if no way can be identified to get the source. """ filename = getfile(object) - all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:] - all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:] + all_bytecode_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:] if any(filename.endswith(s) for s in all_bytecode_suffixes): filename = (os.path.splitext(filename)[0] + importlib.machinery.SOURCE_SUFFIXES[0]) From a22637b472d6c4421bb9206cec56c017dfac1165 Mon Sep 17 00:00:00 2001 From: "Tomas R." Date: Tue, 7 Jan 2025 23:38:34 +0100 Subject: [PATCH 10/14] Improve deprecation message Co-authored-by: Brett Cannon --- Lib/importlib/machinery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py index 7e71f5035d0ae5..63d726445c3d96 100644 --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -36,13 +36,13 @@ def __getattr__(name): if name == 'DEBUG_BYTECODE_SUFFIXES': warnings.warn('importlib.machinery.DEBUG_BYTECODE_SUFFIXES is ' - 'deprecated. Use importlib.machinery.BYTECODE_SUFFIXES ' + 'deprecated; use importlib.machinery.BYTECODE_SUFFIXES ' 'instead.', DeprecationWarning, stacklevel=2) return _DEBUG_BYTECODE_SUFFIXES elif name == 'OPTIMIZED_BYTECODE_SUFFIXES': warnings.warn('importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES is ' - 'deprecated. Use importlib.machinery.BYTECODE_SUFFIXES ' + 'deprecated; use importlib.machinery.BYTECODE_SUFFIXES ' 'instead.', DeprecationWarning, stacklevel=2) return _OPTIMIZED_BYTECODE_SUFFIXES From 60d20c047032bd6da77c31d0fcc6e1edfa485e2e Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Tue, 7 Jan 2025 23:57:03 +0100 Subject: [PATCH 11/14] Raise DeprecationWarning in find_spec instead of __init__ --- Lib/importlib/_bootstrap_external.py | 15 +++++++-------- Lib/test/test_importlib/test_api.py | 5 ----- Lib/test/test_importlib/test_windows.py | 6 ++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 5cca5177d3224d..ff243f6694e40b 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -692,14 +692,6 @@ class WindowsRegistryFinder: '\\Modules\\{fullname}\\Debug') DEBUG_BUILD = (_MS_WINDOWS and '_d.pyd' in EXTENSION_SUFFIXES) - def __init__(self): - import warnings - warnings.warn('importlib.machinery.WindowsRegistryFinder is ' - 'deprecated. Use site configuration instead. ' - 'Future versions of Python may not enable this ' - 'finder by default.', - DeprecationWarning, stacklevel=2) - @staticmethod def _open_registry(key): try: @@ -724,6 +716,13 @@ def _search_registry(cls, fullname): @classmethod def find_spec(cls, fullname, path=None, target=None): + import warnings + warnings.warn('importlib.machinery.WindowsRegistryFinder is ' + 'deprecated; use site configuration instead. ' + 'Future versions of Python may not enable this ' + 'finder by default.', + DeprecationWarning, stacklevel=2) + filepath = cls._search_registry(fullname) if filepath is None: return None diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index 20308d2e6e0b57..6035b2ca72efb9 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -504,11 +504,6 @@ def test_machinery_deprecated_attributes(self): with self.assertWarns(DeprecationWarning): getattr(machinery, attr) - def test_deprecated_windows_registry_finder(self): - from importlib.machinery import WindowsRegistryFinder - with self.assertWarns(DeprecationWarning): - WindowsRegistryFinder() - if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_importlib/test_windows.py b/Lib/test/test_importlib/test_windows.py index 8a9a8fffcd10d4..f32680bdbeb9e3 100644 --- a/Lib/test/test_importlib/test_windows.py +++ b/Lib/test/test_importlib/test_windows.py @@ -104,6 +104,12 @@ def test_module_not_found(self): spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module) self.assertIsNone(spec) + def test_raises_deprecation_warning(self): + # WindowsRegistryFinder is not meant to be instantiated, so the + # deprecation warning is raised in the 'find_spec' method instead. + with self.assertWarns(DeprecationWarning): + self.machinery.WindowsRegistryFinder.find_spec('spam') + (Frozen_WindowsRegistryFinderTests, Source_WindowsRegistryFinderTests ) = test_util.test_both(WindowsRegistryFinderTests, machinery=machinery) From f3faa954056cf13d5d1073bca3473cff55c4136a Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Tue, 7 Jan 2025 23:59:30 +0100 Subject: [PATCH 12/14] Remove extra import --- Lib/importlib/_bootstrap_external.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index ff243f6694e40b..1e5da291fb045e 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -716,8 +716,7 @@ def _search_registry(cls, fullname): @classmethod def find_spec(cls, fullname, path=None, target=None): - import warnings - warnings.warn('importlib.machinery.WindowsRegistryFinder is ' + _warnings.warn('importlib.machinery.WindowsRegistryFinder is ' 'deprecated; use site configuration instead. ' 'Future versions of Python may not enable this ' 'finder by default.', From 5fa376cadfc1a16531d5a9ed566405e1226c7403 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Wed, 8 Jan 2025 00:00:49 +0100 Subject: [PATCH 13/14] Align code --- Lib/importlib/_bootstrap_external.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 1e5da291fb045e..697f7c55218a8f 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -717,10 +717,10 @@ def _search_registry(cls, fullname): @classmethod def find_spec(cls, fullname, path=None, target=None): _warnings.warn('importlib.machinery.WindowsRegistryFinder is ' - 'deprecated; use site configuration instead. ' - 'Future versions of Python may not enable this ' - 'finder by default.', - DeprecationWarning, stacklevel=2) + 'deprecated; use site configuration instead. ' + 'Future versions of Python may not enable this ' + 'finder by default.', + DeprecationWarning, stacklevel=2) filepath = cls._search_registry(fullname) if filepath is None: From adccc7d9ae581e66a4adbde7cfd39657af6e0e17 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 14 Jan 2025 15:09:11 -0800 Subject: [PATCH 14/14] Update news entry to be more specific about what's deprecated --- .../next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst b/Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst index 1f4449b475482a..9a6fce8647cc6b 100644 --- a/Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst +++ b/Misc/NEWS.d/next/Library/2024-12-16-22-20-38.gh-issue-121604.m3Xn4G.rst @@ -1 +1 @@ -Add missing Deprecation warnings for several :mod:`importlib` members. +Add missing Deprecation warnings for :attr:`importlib.machinery.DEBUG_BYTECODE_SUFFIXES`, :attr:`importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES`, :class:`importlib.machinery.WindowsRegistryFinder`, :class:`importlib.abc.ResourceLoader`, :meth:`importlib.abc.SourceLoader.path_mtime`.