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
2 changes: 1 addition & 1 deletion Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ def _unify_values(self, section, vars):
def _convert_to_boolean(self, value):
"""Return a boolean value translating from other types if necessary.
"""
if value.lower() not in self.BOOLEAN_STATES:
if value is None or value.lower() not in self.BOOLEAN_STATES:
raise ValueError('Not a boolean: %s' % value)
return self.BOOLEAN_STATES[value.lower()]

Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,14 @@ def test_other_errors(self):
class ConfigParserTestCaseNoValue(ConfigParserTestCase):
allow_no_value = True

def test_getboolean_with_no_value(self):
cf = self.fromstring("[section]\noption\n")

with self.assertRaisesRegex(ValueError, "Not a boolean: None"):
cf.getboolean("section", "option")
with self.assertRaisesRegex(ValueError, "Not a boolean: None"):
cf["section"].getboolean("option")


class NoValueAndExtendedInterpolation(CfgParserTestCaseClass):
interpolation = configparser.ExtendedInterpolation()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`configparser.ConfigParser` now raises :exc:`ValueError` instead of
:exc:`AttributeError` when :meth:`~configparser.ConfigParser.getboolean` is
called on an option without a value while ``allow_no_value=True``.
Loading