[3.12] gh-116957: configparser: Do post-process values after DuplicateOptionError (GH-116958) by drothlis · Pull Request #117013 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
180 changes: 91 additions & 89 deletions Lib/configparser.py
15 changes: 15 additions & 0 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,21 @@ def test_weird_errors(self):
"'opt' in section 'Bar' already exists")
self.assertEqual(e.args, ("Bar", "opt", "<dict>", None))

def test_get_after_duplicate_option_error(self):
cf = self.newconfig()
ini = textwrap.dedent("""\
[Foo]
x{equals}1
y{equals}2
y{equals}3
""".format(equals=self.delimiters[0]))
if self.strict:
with self.assertRaises(configparser.DuplicateOptionError):
cf.read_string(ini)
else:
cf.read_string(ini)
self.assertEqual(cf.get('Foo', 'x'), '1')

def test_write(self):
config_string = (
"[Long Line]\n"
Expand Down