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
2 changes: 2 additions & 0 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
except (KeyError, NoSectionError, NoOptionError):
raise InterpolationMissingOptionError(
option, section, rawval, ":".join(path)) from None
if v is None:
continue
if "$" in v:
self._interpolate_some(parser, opt, accum, v, sect,
dict(parser.items(sect, raw=True)),
Expand Down
41 changes: 41 additions & 0 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,47 @@ class ConfigParserTestCaseNoValue(ConfigParserTestCase):
allow_no_value = True


class NoValueAndExtendedInterpolation(CfgParserTestCaseClass):
interpolation = configparser.ExtendedInterpolation()
allow_no_value = True

def test_interpolation_with_allow_no_value(self):
config = textwrap.dedent("""
[dummy]
a
b = ${a}
""")
cf = self.fromstring(config)

self.assertIs(cf["dummy"]["a"], None)
self.assertEqual(cf["dummy"]["b"], "")

def test_explicit_none(self):
config = textwrap.dedent("""
[dummy]
a = None
b = ${a}
""")
cf = self.fromstring(config)

self.assertEqual(cf["dummy"]["a"], "None")
self.assertEqual(cf["dummy"]["b"], "None")


class ConfigParserNoValueAndExtendedInterpolationTest(
NoValueAndExtendedInterpolation,
unittest.TestCase,
):
config_class = configparser.ConfigParser


class RawConfigParserNoValueAndExtendedInterpolationTest(
NoValueAndExtendedInterpolation,
unittest.TestCase,
):
config_class = configparser.RawConfigParser


class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase):
config_class = configparser.ConfigParser
delimiters = {'='}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :class:`configparser.ConfigParser` parsing empty interpolation with
``allow_no_value`` set to ``True``.
Loading