python / python/cpython

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

オープン
#155,436 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ConfigParser.getboolean() のエントリーポイントから始め、issue にある値のないオプションのケースを再現します。boolean 変換に関する既存の configparser テストを確認し、None に対して文書化されている ValueError が発生することを示すテストカバレッジを追加します。このケースで AttributeError が発生しなくなれば作業完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。