[Python-checkins] bpo-43720: Update import-related stdlib deprecation messages to say they will be removed in Python 3.12 (GH-25167)

brettcannon webhook-mailer at python.org
Sat Apr 3 18:31:22 EDT 2021


https://github.com/python/cpython/commit/dc6d3e1e4c0c1e4b2210edab8fb4762569dc2936
commit: dc6d3e1e4c0c1e4b2210edab8fb4762569dc2936
branch: master
author: Brett Cannon <brett at python.org>
committer: brettcannon <brett at python.org>
date: 2021-04-03T15:31:15-07:00
summary:

bpo-43720: Update import-related stdlib deprecation messages to say they will be removed in Python 3.12 (GH-25167)

files:
A Misc/NEWS.d/next/Library/2021-04-03-13-45-51.bpo-43720.FDZ5cZ.rst
M Lib/imp.py
M Lib/importlib/util.py
M Lib/pkgutil.py
M Lib/test/test_pkgutil.py

diff --git a/Lib/imp.py b/Lib/imp.py
index 31f8c766381ad..e02aaef344c61 100644
--- a/Lib/imp.py
+++ b/Lib/imp.py
@@ -28,7 +28,8 @@
 import types
 import warnings
 
-warnings.warn("the imp module is deprecated in favour of importlib; "
+warnings.warn("the imp module is deprecated in favour of importlib and slated "
+              "for removal in Python 3.12; "
               "see the module's documentation for alternative uses",
               DeprecationWarning, stacklevel=2)
 
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py
index 98a0fa54dfd87..8623c89840c6a 100644
--- a/Lib/importlib/util.py
+++ b/Lib/importlib/util.py
@@ -149,7 +149,8 @@ def set_package(fxn):
     """
     @functools.wraps(fxn)
     def set_package_wrapper(*args, **kwargs):
-        warnings.warn('The import system now takes care of this automatically.',
+        warnings.warn('The import system now takes care of this automatically; '
+                      'this decorator is slated for removal in Python 3.12',
                       DeprecationWarning, stacklevel=2)
         module = fxn(*args, **kwargs)
         if getattr(module, '__package__', None) is None:
@@ -168,7 +169,8 @@ def set_loader(fxn):
     """
     @functools.wraps(fxn)
     def set_loader_wrapper(self, *args, **kwargs):
-        warnings.warn('The import system now takes care of this automatically.',
+        warnings.warn('The import system now takes care of this automatically; '
+                      'this decorator is slated for removal in Python 3.12',
                       DeprecationWarning, stacklevel=2)
         module = fxn(self, *args, **kwargs)
         if getattr(module, '__loader__', None) is None:
@@ -195,7 +197,8 @@ def module_for_loader(fxn):
     the second argument.
 
     """
-    warnings.warn('The import system now takes care of this automatically.',
+    warnings.warn('The import system now takes care of this automatically; '
+                  'this decorator is slated for removal in Python 3.12',
                   DeprecationWarning, stacklevel=2)
     @functools.wraps(fxn)
     def module_for_loader_wrapper(self, fullname, *args, **kwargs):
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 3d7f19f39981d..2c3429856be46 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -204,7 +204,8 @@ class ImpImporter:
 
     def __init__(self, path=None):
         global imp
-        warnings.warn("This emulation is deprecated, use 'importlib' instead",
+        warnings.warn("This emulation is deprecated and slated for removal "
+                      "in Python 3.12; use 'importlib' instead",
              DeprecationWarning)
         _import_imp()
         self.path = path
@@ -271,7 +272,8 @@ class ImpLoader:
     code = source = None
 
     def __init__(self, fullname, file, filename, etc):
-        warnings.warn("This emulation is deprecated, use 'importlib' instead",
+        warnings.warn("This emulation is deprecated and slated for removal in "
+                      "Python 3.12; use 'importlib' instead",
                       DeprecationWarning)
         _import_imp()
         self.file = file
diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py
index bf9722a229611..6e3618f6b0f98 100644
--- a/Lib/test/test_pkgutil.py
+++ b/Lib/test/test_pkgutil.py
@@ -498,7 +498,8 @@ class ImportlibMigrationTests(unittest.TestCase):
 
     def check_deprecated(self):
         return check_warnings(
-            ("This emulation is deprecated, use 'importlib' instead",
+            ("This emulation is deprecated and slated for removal in "
+             "Python 3.12; use 'importlib' instead",
              DeprecationWarning))
 
     def test_importer_deprecated(self):
diff --git a/Misc/NEWS.d/next/Library/2021-04-03-13-45-51.bpo-43720.FDZ5cZ.rst b/Misc/NEWS.d/next/Library/2021-04-03-13-45-51.bpo-43720.FDZ5cZ.rst
new file mode 100644
index 0000000000000..d71460f010dcc
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-04-03-13-45-51.bpo-43720.FDZ5cZ.rst
@@ -0,0 +1,2 @@
+Document various stdlib deprecations in imp, pkgutil, and importlib.util for removal in Python
+3.12.



More information about the Python-checkins mailing list