8000 gh-104886: Remove deprecated configparser.LegacyInterpolation (#104887) · python/cpython@3f9c60f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f9c60f

Browse files
hugovkvstinner
andauthored
gh-104886: Remove deprecated configparser.LegacyInterpolation (#104887)
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 0242e9a commit 3f9c60f

File tree

5 files changed

+12
-91
lines changed

5 files changed

+12
-91
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ Removed
118118
* Remove support for using :class:`pathlib.Path` objects as context managers.
119119
This functionality was deprecated and made a no-op in Python 3.9.
120120

121+
* Remove the undocumented :class:`!configparser.LegacyInterpolation` class,
122+
deprecated in the docstring since Python 3.2,
123+
and with a deprecation warning since Python 3.11.
124+
(Contributed by Hugo van Kemenade in :gh:`104886`.)
125+
121126
* Remove the :meth:`!turtle.RawTurtle.settiltangle` method,
122127
deprecated in docs since Python 3.1
123128
and with a deprecation warning since Python 3.11.
@@ -135,6 +140,8 @@ Removed
135140
* :meth:`unittest.TestLoader.loadTestsFromTestCase`
136141
* :meth:`unittest.TestLoader.getTestCaseNames`
137142

143+
(Contributed by Hugo van Kemenade in :gh:`104835`.)
144+
138145
* :pep:`594`: Remove the :mod:`!cgi`` and :mod:`!cgitb` modules,
139146
deprecated in Python 3.11.
140147

Lib/configparser.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"ParsingError", "MissingSectionHeaderError",
156156
"ConfigParser", "RawConfigParser",
157157
"Interpolation", "BasicInterpolation", "ExtendedInterpolation",
158-
"LegacyInterpolation", "SectionProxy", "ConverterMapping",
158+
"SectionProxy", "ConverterMapping",
159159
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH")
160160

161161
_default_dict = dict
@@ -491,53 +491,6 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
491491
"found: %r" % (rest,))
492492

493493

494-
class LegacyInterpolation(Interpolation):
495-
"""Deprecated interpolation used in old versions of ConfigParser.
496-
Use BasicInterpolation or ExtendedInterpolation instead."""
497-
498-
_KEYCRE = re.compile(r"%\(([^)]*)\)s|.")
499-
500-
def __init__(self, *args, **kwargs):
501-
super().__init__(*args, **kwargs)
502-
warnings.warn(
503-
"LegacyInterpolation has been deprecated since Python 3.2 "
504-
"and will be removed from the configparser module in Python 3.13. "
505-
"Use BasicInterpolation or ExtendedInterpolation instead.",
506-
DeprecationWarning, stacklevel=2
507-
)
508-
509-
def before_get(self, parser, section, option, value, vars):
510-
rawval = value
511-
depth = MAX_INTERPOLATION_DEPTH
512-
while depth: # Loop through this until it's done
513-
depth -= 1
514-
if value and "%(" in value:
515-
replace = functools.partial(self._interpolation_replace,
516-
parser=parser)
517-
value = self._KEYCRE.sub(replace, value)
518-
try:
519-
value = value % vars
520-
except KeyError as e:
521-
raise InterpolationMissingOptionError(
522-
option, section, rawval, e.args[0]) from None
523-
else:
524-
break
525-
if value and "%(" in value:
526-
raise InterpolationDepthError(option, section, rawval)
527-
return value
528-
529-
def before_set(self, parser, section, option, value):
530-
return value
531-
532-
@staticmethod
533-
def _interpolation_replace(match, parser):
534-
s = match.group(1)
535-
if s is None:
536-
return match.group()
537-
else:
538-
return "%%(%s)s" % parser.optionxform(s)
539-
540-
541494
class RawConfigParser(MutableMapping):
542495
"""ConfigParser that does not do interpolation."""
543496

Lib/test/test_configparser.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,6 @@ def test_interpolation(self):
907907
if self.interpolation == configparser._UNSET:
908908
self.assertEqual(e.args, ("bar11", "Foo",
909909
"something %(with11)s lots of interpolation (11 steps)"))
910-
elif isinstance(self.interpolation, configparser.LegacyInterpolation):
911-
self.assertEqual(e.args, ("bar11", "Foo",
912-
"something %(with11)s lots of interpolation (11 steps)"))
913910

914911
def test_interpolation_missing_value(self):
915912
cf = self.get_interpolation_config()
@@ -921,9 +918,6 @@ def test_interpolation_missing_value(self):
921918
if self.interpolation == configparser._UNSET:
922919
self.assertEqual(e.args, ('name', 'Interpolation Error',
923920
'%(reference)s', 'reference'))
924-
elif isinstance(self.interpolation, configparser.LegacyInterpolation):
925-
self.assertEqual(e.args, ('name', 'Interpolation Error',
926-
'%(reference)s', 'reference'))
927921

928922
def test_items(self):
929923
self.check_items_config([('default', '<default>'),
@@ -942,9 +936,6 @@ def test_safe_interpolation(self):
942936
self.assertEqual(cf.get("section", "ok"), "xxx/%s")
943937
if self.interpolation == configparser._UNSET:
944938
self.assertEqual(cf.get("section", "not_ok"), "xxx/xxx/%s")
945-
elif isinstance(self.interpolation, configparser.LegacyInterpolation):
946-
with self.assertRaises(TypeError):
947-
cf.get("section", "not_ok")
948939

949940
def test_set_malformatted_interpolation(self):
950941
cf = self.fromstring("[sect]\n"
@@ -1025,31 +1016,6 @@ class CustomConfigParser(configparser.ConfigParser):
10251016
cf.read_string(self.ini)
10261017
self.assertMatchesIni(cf)
10271018

1028-
1029-
class ConfigParserTestCaseLegacyInterpolation(ConfigParserTestCase):
1030-
config_class = configparser.ConfigParser
1031-
with warnings.catch_warnings():
1032-
warnings.simplefilter("ignore", DeprecationWarning)
1033-
interpolation = configparser.LegacyInterpolation()
1034-
1035-
def test_set_malformatted_interpolation(self):
1036-
cf = self.fromstring("[sect]\n"
1037-
"option1{eq}foo\n".format(eq=self.delimiters[0]))
1038-
1039-
self.assertEqual(cf.get('sect', "option1"), "foo")
1040-
1041-
cf.set("sect", "option1", "%foo")
1042-
self.assertEqual(cf.get('sect', "option1"), "%foo")
1043-
cf.set("sect", "option1", "foo%")
1044-
self.assertEqual(cf.get('sect', "option1"), "foo%")
1045-
cf.set("sect", "option1", "f%oo")
1046-
self.assertEqual(cf.get('sect', "option1"), "f%oo")
1047-
1048-
# bug #5741: double percents are *not* malformed
1049-
cf.set("sect", "option2", "foo%%bar")
1050-
self.assertEqual(cf.get("sect", "option2"), "foo%%bar")
1051-
1052-
10531019
class ConfigParserTestCaseInvalidInterpolationType(unittest.TestCase):
10541020
def test_error_on_wrong_type_for_interpolation(self):
10551021
for value in [configparser.ExtendedInterpolation, 42, "a string"]:
@@ -1636,14 +1602,6 @@ def test_interpolation_validation(self):
16361602
self.assertEqual(str(cm.exception), "bad interpolation variable "
16371603
"reference '%(()'")
16381604

1639-
def test_legacyinterpolation_deprecation(self):
1640-
with warnings.catch_warnings(record=True) as w:
1641-
warnings.simplefilter("always", DeprecationWarning)
1642-
configparser.LegacyInterpolation()
1643-
self.assertGreaterEqual(len(w), 1)
1644-
for warning in w:
1645-
self.assertIs(warning.category, DeprecationWarning)
1646-
16471605
def test_sectionproxy_repr(self):
16481606
parser = configparser.ConfigParser()
16491607
parser.read_string("""

Misc/NEWS.d/3.11.0a7.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ references in :ref:`PEP 585 generic aliases <types-genericalias>`.
989989
.. nonce: xnhT4a
990990
.. section: Library
991991
992-
Add :exc:`DeprecationWarning` to :class:`LegacyInterpolation`, deprecated in
992+
Add :exc:`DeprecationWarning` to :class:`!LegacyInterpolation`, deprecated in
993993
the docstring since Python 3.2. Will be removed in Python 3.13. Use
994994
:class:`BasicInterpolation` or :class:`ExtendedInterpolation` instead.
995995

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove the undocumented :class:`!configparser.LegacyInterpolation` class,
2+
deprecated in the docstring since Python 3.2, and with a deprecation warning
3+
since Python 3.11. Patch by Hugo van Kemenade.

0 commit comments

Comments
 (0)
0