diff --git a/Lib/configparser.py b/Lib/configparser.py index b7a0b0b56893c5f..34060cb904689ad 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -593,13 +593,17 @@ def _interpolate_some( 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)), + submap, depth + 1, ) else: diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index 61b8d1c527d3472..b83a5317a72879d 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -1494,6 +1494,24 @@ def test_other_errors(self): with self.assertRaises(ValueError): cf['interpolation fail']['case6'] = "BLACK $ABBATH" + def test_get_with_vars_nested(self): + # gh-70999: honor vars at all levels of same-section interpolation + 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') + class ConfigParserTestCaseNoValue(ConfigParserTestCase): allow_no_value = True diff --git a/Misc/NEWS.d/next/Library/2026-08-15-12-00-00.gh-issue-70999.NZ96LZ.rst b/Misc/NEWS.d/next/Library/2026-08-15-12-00-00.gh-issue-70999.NZ96LZ.rst new file mode 100644 index 000000000000000..3fab7ece4994d63 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-15-12-00-00.gh-issue-70999.NZ96LZ.rst @@ -0,0 +1,3 @@ +Fix :class:`configparser.ExtendedInterpolation` dropping caller-supplied +``vars`` during nested interpolation within a section. Patch by Nikolaus +Schuetz.