Skip to content

Commit 2aa86b8

Browse files
committed
bpo-46607: Add DeprecationWarning for LegacyInterpolation, deprecated in docs since 3.2
1 parent 6baa98e commit 2aa86b8

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ Deprecated
473473

474474
(Contributed by Hugo van Kemenade in :issue:`45173`.)
475475

476+
* :class:`configparser.LegacyInterpolation` has been deprecated in the docstring
477+
since Python 3.2. It now emits a :exc:`DeprecationWarning` and will be removed
478+
in Python 3.13. Use :class:`configparser.BasicInterpolation` or
479+
:class:`configparser.ExtendedInterpolation instead.
480+
(Contributed by Hugo van Kemenade in :issue:`46607`.)
476481

477482
Removed
478483
=======

Lib/configparser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,15 @@ class LegacyInterpolation(Interpolation):
525525

526526
_KEYCRE = re.compile(r"%\(([^)]*)\)s|.")
527527

528+
def __init__(self, *args, **kwargs):
529+
super().__init__(*args, **kwargs)
530+
warnings.warn(
531+
"LegacyInterpolation has been deprecated since Python 3.2 "
532+
"and will be removed from the configparser module in Python 3.13. "
533+
"Use BasicInterpolation or ExtendedInterpolation instead.",
534+
DeprecationWarning, stacklevel=2
535+
)
536+
528537
def before_get(self, parser, section, option, value, vars):
529538
rawval = value
530539
depth = MAX_INTERPOLATION_DEPTH

Lib/test/test_configparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,14 @@ def test_safeconfigparser_deprecation(self):
16581658
for warning in w:
16591659
self.assertTrue(warning.category is DeprecationWarning)
16601660

1661+
def test_legacyinterpolation_deprecation(self):
1662+
with warnings.catch_warnings(record=True) as w:
1663+
warnings.simplefilter("always", DeprecationWarning)
1664+
configparser.LegacyInterpolation()
1665+
self.assertGreaterEqual(len(w), 1)
1666+
for warning in w:
1667+
self.assertIs(warning.category, DeprecationWarning)
1668+
16611669
def test_sectionproxy_repr(self):
16621670
parser = configparser.ConfigParser()
16631671
parser.read_string("""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add :exc:`DeprecationWarning` to :class:`LegacyInterpolation`, deprecated in
2+
the docstring since Python 3.2. Will be removed in Python 3.13. Use
3+
:class:`BasicInterpolation` or :class:`ExtendedInterpolation` instead.

0 commit comments

Comments
 (0)