bpo-46607: Add DeprecationWarning for LegacyInterpolation, deprecated in docs since 3.2 (GH-30927)

This commit is contained in:
Hugo van Kemenade 2022-04-05 18:15:11 +03:00 committed by GitHub
parent cfb849a326
commit 75280944e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View 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

View 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

View 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("""

View File

@ -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.