FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-46607: Add DeprecationWarning to LegacyInterpolation by hugovk · Pull Request #30927 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.11.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,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
Expand Down
9 changes: 9 additions & 0 deletions Lib/configparser.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_configparser.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,14 @@ def test_safeconfigparser_deprecation(self):
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("""
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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.

Back | FazBrowse Home | New Git URL