]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46607: Add DeprecationWarning for LegacyInterpolation, deprecated in docs since...
authorHugo van Kemenade <hugovk@users.noreply.github.com>
Tue, 5 Apr 2022 15:15:11 +0000 (18:15 +0300)
committerGitHub <noreply@github.com>
Tue, 5 Apr 2022 15:15:11 +0000 (08:15 -0700)
Doc/whatsnew/3.11.rst
Lib/configparser.py
Lib/test/test_configparser.py
Misc/NEWS.d/next/Library/2022-01-26-18-30-34.bpo-46607.xnhT4a.rst [new file with mode: 0644]

index c312645c31cd79bcfd4869f29f9576b60b0da4cd..537fa49fd2f28ca8eb08ab787b1e8fa27e090642 100644 (file)
@@ -590,6 +590,12 @@ Deprecated
 
   (Contributed by Hugo van Kemenade in :issue:`45173`.)
 
+* :class:`configparser.LegacyInterpolation` has been deprecated in the docstring
+  since Python 3.2. It now emits a :exc:`DeprecationWarning` and will be removed
+  in Python 3.13. Use :class:`configparser.BasicInterpolation` or
+  :class:`configparser.ExtendedInterpolation instead.
+  (Contributed by Hugo van Kemenade in :issue:`46607`.)
+
 * The :func:`locale.getdefaultlocale` function is deprecated and will be
   removed in Python 3.13. Use :func:`locale.setlocale`,
   :func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and
index f5666f518f121d9195474729dee3c61ef8543c7b..de9ee537ac188464053d4f9e9e22f3a27421164b 100644 (file)
@@ -525,6 +525,15 @@ class LegacyInterpolation(Interpolation):
 
     _KEYCRE = re.compile(r"%\(([^)]*)\)s|.")
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        warnings.warn(
+            "LegacyInterpolation has been deprecated since Python 3.2 "
+            "and will be removed from the configparser module in Python 3.13. "
+            "Use BasicInterpolation or ExtendedInterpolation instead.",
+            DeprecationWarning, stacklevel=2
+        )
+
     def before_get(self, parser, section, option, value, vars):
         rawval = value
         depth = MAX_INTERPOLATION_DEPTH
index 569959c3ed9198fe369584f483c366941966c91e..efd98ffb67a546f8443b34602e79d6597b2129c3 100644 (file)
@@ -1666,6 +1666,14 @@ class CoverageOneHundredTestCase(unittest.TestCase):
         for warning in w:
             self.assertTrue(warning.category is DeprecationWarning)
 
+    def test_legacyinterpolation_deprecation(self):
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always", DeprecationWarning)
+            configparser.LegacyInterpolation()
+        self.assertGreaterEqual(len(w), 1)
+        for warning in w:
+            self.assertIs(warning.category, DeprecationWarning)
+
     def test_sectionproxy_repr(self):
         parser = configparser.ConfigParser()
         parser.read_string("""
diff --git a/Misc/NEWS.d/next/Library/2022-01-26-18-30-34.bpo-46607.xnhT4a.rst b/Misc/NEWS.d/next/Library/2022-01-26-18-30-34.bpo-46607.xnhT4a.rst
new file mode 100644 (file)
index 0000000..e0c7ed0
--- /dev/null
@@ -0,0 +1,3 @@
+Add :exc:`DeprecationWarning` to :class:`LegacyInterpolation`, deprecated in
+the docstring since Python 3.2. Will be removed in Python 3.13. Use
+:class:`BasicInterpolation` or :class:`ExtendedInterpolation` instead.