Skip to content
Open
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
7 changes: 5 additions & 2 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,12 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
if v is None:
continue
if "$" in v:
if sect == section:
submap = map
else:
submap = dict(parser.items(sect, raw=True))
self._interpolate_some(parser, opt, accum, v, sect,
dict(parser.items(sect, raw=True)),
depth + 1)
submap, depth + 1)
else:
accum.append(v)
else:
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,25 @@ def test_other_errors(self):
with self.assertRaises(ValueError):
cf['interpolation fail']['case6'] = "BLACK $ABBATH"

def test_get_with_vars_nested(self):
# gh-70999: caller-supplied ``vars`` must be honoured at every level
# of a same-section interpolation chain, not just the first.
cf = self.fromstring(textwrap.dedent("""
[section]
a = ${b}
b = ${c}
c = default

[cross]
via = ${section:c}
""").strip())

eq = self.assertEqual
eq(cf.get('section', 'b', vars={'c': 'OVERRIDE'}), 'OVERRIDE')
eq(cf.get('section', 'a', vars={'c': 'OVERRIDE'}), 'OVERRIDE')
eq(cf.get('section', 'a'), 'default')
eq(cf.get('cross', 'via', vars={'c': 'OVERRIDE'}), 'default')
Comment on lines +1377 to +1381

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that asserts speak for themselves and the comments here are a bit verbose. The above gh-70999 reference is enough.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed those — the asserts stand on their own now, with just the gh-70999 reference kept. Thanks!



class ConfigParserTestCaseNoValue(ConfigParserTestCase):
allow_no_value = True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :class:`configparser.ExtendedInterpolation` dropping caller-supplied
``vars`` during nested interpolation within a section. Patch by Nikolaus
Schuetz.
Loading