Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Raise DeprecationWarning in find_spec instead of __init__
  • Loading branch information
tomasr8 committed Jan 7, 2025
commit 60d20c047032bd6da77c31d0fcc6e1edfa485e2e
15 changes: 7 additions & 8 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions Lib/test/test_importlib/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions Lib/test/test_importlib/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading