python / python/cpython

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

Open
#155,436 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-155437

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ConfigParser.getboolean() entry point and reproduce the value-less option case from the issue. Check the existing configparser tests for boolean conversion and add coverage showing the documented ValueError for None; the work is done when this case no longer raises AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.