Skip to content

Commit 7528094

Browse files
authored
bpo-46607: Add DeprecationWarning for LegacyInterpolation, deprecated in docs since 3.2 (GH-30927)
1 parent cfb849a commit 7528094

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ Deprecated
590590

591591
(Contributed by Hugo van Kemenade in :issue:`45173`.)
592592

593+
* :class:`configparser.LegacyInterpolation` has been deprecated in the docstring
594+
since Python 3.2. It now emits a :exc:`DeprecationWarning` and will be removed
595+
in Python 3.13. Use :class:`configparser.BasicInterpolation` or
596+
:class:`configparser.ExtendedInterpolation instead.
597+
(Contributed by Hugo van Kemenade in :issue:`46607`.)
598+
593599
* The :func:`locale.getdefaultlocale` function is deprecated and will be
594600
removed in Python 3.13. Use :func:`locale.setlocale`,
595601
:func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and

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
@@ -1666,6 +1666,14 @@ def test_safeconfigparser_deprecation(self):
16661666
for warning in w:
16671667
self.assertTrue(warning.category is DeprecationWarning)
16681668

1669+
def test_legacyinterpolation_deprecation(self):
1670+
with warnings.catch_warnings(record=True) as w:
1671+
warnings.simplefilter("always", DeprecationWarning)
1672+
configparser.LegacyInterpolation()
1673+
self.assertGreaterEqual(len(w), 1)
1674+
for warning in w:
1675+
self.assertIs(warning.category, DeprecationWarning)
1676+
16691677
def test_sectionproxy_repr(self):
16701678
parser = configparser.ConfigParser()
16711679
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)