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
4 changes: 4 additions & 0 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ 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)
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = x%(a)sy
"""))
self.assertIsNone(cf["s"]["a"])
self.assertEqual(cf.get("s", "b"), "xy")


class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase):
config_class = configparser.ConfigParser
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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`.
Loading