8000 gh-121604: Make sure all deprecated items in importlib raise DeprecationWarning by tomasr8 · Pull Request #128007 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-121604: Make sure all deprecated items in importlib raise DeprecationWarning #128007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 15, 2025
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
Add DeprecationWarning for WindowsRegistryFinder
Co-authored-by: rashansmith <smith.rashan@gmail.com>
  • Loading branch information
tomasr8 and rashansmith committed Dec 16, 2024
commit 5375cf6be019e038b10355d596eb300f69694d01
8 changes: 8 additions & 0 deletions Lib/importlib/_bootstrap_external.py
8000
Original file line numberDiff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Lib/importlib/machinery.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def all_suffixes():

def __getattr__(name):
import warnings

if name == 'DEBUG_BYTECODE_SUFFIXES':
warnings.warn(" B16C ;importlib.machinery.DEBUG_BYTECODE_SUFFIXES is "
"deprecated. Use importlib.machinery.BYTECODE_SUFFIXES "
Expand Down
9 changes: 7 additions & 2 deletions Lib/test/test_importlib/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
0