diff --git a/Lib/configparser.py b/Lib/configparser.py index 3c452afe8ade485..9e3d9793ef060c8 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -471,6 +471,8 @@ def _interpolate_some(self, parser, option, accum, rest, section, map, except KeyError: raise InterpolationMissingOptionError( option, section, rawval, var) from None + if v is None: + continue if "%" in v: self._interpolate_some(parser, option, accum, v, section, map, depth + 1) diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index 4783943f71a1092..4ec52a74e1035fc 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -1379,6 +1379,17 @@ class RawConfigParserNoValueAndExtendedInterpolationTest( ): config_class = configparser.RawConfigParser +class BasicInterpolationWithAllowNoValueTest(unittest.TestCase): + def test_interpolation_with_allow_no_value(self): + cf = configparser.ConfigParser(allow_no_value=True) + cf.read_string(textwrap.dedent(""" + [s] + a + b = %(a)s + """)) + self.assertIsNone(cf["s"]["a"]) + self.assertEqual(cf.get("s", "b"), "") + class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase): config_class = configparser.ConfigParser diff --git a/Misc/NEWS.d/next/Library/2026-07-17-18-53-45.gh-issue-153855.h6YZOX.rst b/Misc/NEWS.d/next/Library/2026-07-17-18-53-45.gh-issue-153855.h6YZOX.rst new file mode 100644 index 000000000000000..a4d05d63c9ccf59 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-17-18-53-45.gh-issue-153855.h6YZOX.rst @@ -0,0 +1,4 @@ +Fix :class:`configparser.BasicInterpolation` raising ``TypeError`` when +interpolating a reference to a value-less option with +``allow_no_value=True``; it now treats the missing value as empty, like +:class:`configparser.ExtendedInterpolation`.