8000 gh-89336: Remove configparser APIs that were deprecated for 3.12 by gpshead · Pull Request #92503 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-89336: Remove configparser APIs that were deprecated for 3.12 #92503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix the tests, further cleanup.
  • Loading branch information
gpshead committed May 8, 2022
commit d22fac1ec73b0a3f7f71127f3aab1db044e986de
19 changes: 5 additions & 14 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@
import sys
import warnings

__all__ = ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
__all__ = ("NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
"NoOptionError", "InterpolationError", "InterpolationDepthError",
"InterpolationMissingOptionError", "InterpolationSyntaxError",
"ParsingError", "MissingSectionHeaderError",
"ConfigParser", "SafeConfigParser", "RawConfigParser",
"ConfigParser", "RawConfigParser",
"Interpolation", "BasicInterpolation", "ExtendedInterpolation",
"LegacyInterpolation", "SectionProxy", "ConverterMapping",
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH")

_default_dict = dict
DEFAULTSECT = "DEFAULT"
Expand Down Expand Up @@ -297,17 +297,8 @@ def __init__(self, option, section, rawval):
class ParsingError(Error):
"""Raised when a configuration file does not follow legal syntax."""

def __init__(self, source=None, filename=None):
# Exactly one of `source'/`filename' arguments has to be given.
# `filename' kept for compatibility.
if filename and source:
raise ValueError("Cannot specify both `filename' and `source'. "
"Use `source'.")
elif not filename and not source:
raise ValueError("Required argument `source' not given.")
elif filename:
source = filename
Error.__init__(self, 'Source contains parsing errors: %r' % source)
def __init__(self, source):
super().__init__(f'Source contains parsing errors: {source!r}')
self.source = source
self.errors = []
self.args = (source, )
Expand Down
42 changes: 5 additions & 37 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,23 +1612,12 @@ def test_interpolation_depth_error(self):
self.assertEqual(error.section, 'section')

def test_parsing_error(self):
with self.assertRaises(ValueError) as cm:
with self.assertRaises(TypeError) as cm:
configparser.ParsingError()
self.assertEqual(str(cm.exception), "Required argument `source' not "
"given.")
with self.assertRaises(ValueError) as cm:
configparser.ParsingError(source='source', filename='filename')
self.assertEqual(str(cm.exception), "Cannot specify both `filename' "
"and `source'. Use `source'.")
error = configparser.ParsingError(filename='source')
error = configparser.ParsingError(source='source')
self.assertEqual(error.source, 'source')
error = configparser.ParsingError('source')
self.assertEqual(error.source, 'source')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", DeprecationWarning)
self.assertEqual(error.filename, 'source')
error.filename = 'filename'
self.assertEqual(error.source, 'filename')
for warning in w:
self.assertTrue(warning.category is DeprecationWarning)

def test_interpolation_validation(self):
parser = configparser.ConfigParser()
Expand All @@ -1647,27 +1636,6 @@ def test_interpolation_validation(self):
self.assertEqual(str(cm.exception), "bad interpolation variable "
"reference '%(()'")

def test_readfp_deprecation(self):
sio = io.StringIO("""
[section]
option = value
""")
parser = configparser.ConfigParser()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", DeprecationWarning)
parser.readfp(sio, filename='StringIO')
for warning in w:
self.assertTrue(warning.category is DeprecationWarning)
self.assertEqual(len(parser), 2)
self.assertEqual(parser['section']['option'], 'value')

def test_safeconfigparser_deprecation(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", DeprecationWarning)
parser = configparser.SafeConfigParser()
for warning in w:
self.assertTrue(warning.category is Depreca 6EEB tionWarning)

def test_legacyinterpolation_deprecation(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", DeprecationWarning)
Expand Down Expand Up @@ -1841,7 +1809,7 @@ def test_parsingerror(self):
self.assertEqual(e1.source, e2.source)
self.assertEqual(e1.errors, e2.errors)
self.assertEqual(repr(e1), repr(e2))
e1 = configparser.ParsingError(filename='filename')
e1 = configparser.ParsingError('filename')
e1.append(1, 'line1')
e1.append(2, 'line2')
e1.append(3, 'line3')
Expand Down
0