Skip to content

configparser.getboolean() raises AttributeError for a value-less option #155436

Description

@lpyu001

Bug description

When ConfigParser uses allow_no_value=True, calling getboolean() on a value-less option raises AttributeError instead of the documented ValueError.

Documentation:
https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.getboolean

Reproducer

import configparser

config = configparser.ConfigParser(allow_no_value=True)
config.read_string("""
[section]
enabled
""")

assert config.get("section", "enabled") is None
config.getboolean("section", "enabled")

Current result:

AttributeError: 'NoneType' object has no attribute 'lower'

Expected result:

ValueError: Not a boolean: None

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions