Skip to content

Commit dc6d3e1

Browse files
authored
bpo-43720: Update import-related stdlib deprecation messages to say they will be removed in Python 3.12 (GH-25167)
1 parent c5354c0 commit dc6d3e1

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

Lib/imp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import types
2929
import warnings
3030

31-
warnings.warn("the imp module is deprecated in favour of importlib; "
31+
warnings.warn("the imp module is deprecated in favour of importlib and slated "
32+
"for removal in Python 3.12; "
3233
"see the module's documentation for alternative uses",
3334
DeprecationWarning, stacklevel=2)
3435

Lib/importlib/util.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def set_package(fxn):
149149
"""
150150
@functools.wraps(fxn)
151151
def set_package_wrapper(*args, **kwargs):
152-
warnings.warn('The import system now takes care of this automatically.',
152+
warnings.warn('The import system now takes care of this automatically; '
153+
'this decorator is slated for removal in Python 3.12',
153154
DeprecationWarning, stacklevel=2)
154155
module = fxn(*args, **kwargs)
155156
if getattr(module, '__package__', None) is None:
@@ -168,7 +169,8 @@ def set_loader(fxn):
168169
"""
169170
@functools.wraps(fxn)
170171
def set_loader_wrapper(self, *args, **kwargs):
171-
warnings.warn('The import system now takes care of this automatically.',
172+
warnings.warn('The import system now takes care of this automatically; '
173+
'this decorator is slated for removal in Python 3.12',
172174
DeprecationWarning, stacklevel=2)
173175
module = fxn(self, *args, **kwargs)
174176
if getattr(module, '__loader__', None) is None:
@@ -195,7 +197,8 @@ def module_for_loader(fxn):
195197
the second argument.
196198
197199
"""
198-
warnings.warn('The import system now takes care of this automatically.',
200+
warnings.warn('The import system now takes care of this automatically; '
201+
'this decorator is slated for removal in Python 3.12',
199202
DeprecationWarning, stacklevel=2)
200203
@functools.wraps(fxn)
201204
def module_for_loader_wrapper(self, fullname, *args, **kwargs):

Lib/pkgutil.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ class ImpImporter:
204204

205205
def __init__(self, path=None):
206206
global imp
207-
warnings.warn("This emulation is deprecated, use 'importlib' instead",
207+
warnings.warn("This emulation is deprecated and slated for removal "
208+
"in Python 3.12; use 'importlib' instead",
208209
DeprecationWarning)
209210
_import_imp()
210211
self.path = path
@@ -271,7 +272,8 @@ class ImpLoader:
271272
code = source = None
272273

273274
def __init__(self, fullname, file, filename, etc):
274-
warnings.warn("This emulation is deprecated, use 'importlib' instead",
275+
warnings.warn("This emulation is deprecated and slated for removal in "
276+
"Python 3.12; use 'importlib' instead",
275277
DeprecationWarning)
276278
_import_imp()
277279
self.file = file

Lib/test/test_pkgutil.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ class ImportlibMigrationTests(unittest.TestCase):
498498

499499
def check_deprecated(self):
500500
return check_warnings(
501-
("This emulation is deprecated, use 'importlib' instead",
501+
("This emulation is deprecated and slated for removal in "
502+
"Python 3.12; use 'importlib' instead",
502503
DeprecationWarning))
503504

504505
def test_importer_deprecated(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Document various stdlib deprecations in imp, pkgutil, and importlib.util for removal in Python
2+
3.12.

0 commit comments

Comments
 (0)