bpo-46607: Add DeprecationWarning for LegacyInterpolation, deprecated… · python/cpython@7528094 · GitHub
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

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

Doc/whatsnew/3.11.rst

Lines changed: 6 additions & 0 deletions

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

0 commit comments

Comments
 (0)