configparser: BasicInterpolation raises TypeError interpolating a value-less option
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
With allow_no_value=True and the default BasicInterpolation, interpolating a reference to a value-less option raises TypeError instead of resolving or raising a configparser error. ExtendedInterpolation treats the missing value as empty in the same situation.
import configparser
cfg = configparser.ConfigParser(allow_no_value=True)
cfg.read_string("[s]\na\nb = x%(a)sy\n")
cfg.get("s", "b")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cfg.get("s", "b")
~~~~~~~^^^^^^^^^^
File "../Lib/configparser.py", line 855, in get
return self._interpolation.before_get(self, section, option, value,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
d)
^^
File "../Lib/configparser.py", line 433, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "../Lib/configparser.py", line 474, in _interpolate_some
if "%" in v:
^^^^^^^^
TypeError: argument of type 'NoneType' is not a container or iterable
The same pattern with ExtendedInterpolation (b = x${s:a}y) returns "xy".
ExtendedInterpolation._interpolate_some guards this (if v is None: continue, added in gh-130941); BasicInterpolation._interpolate_some does not and reaches if "%" in v: with v set to None (Lib/configparser.py).
Observed on 3.16.0a0.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-153857
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
レポートに記載されているとおり、Lib/configparser.py の BasicInterpolation._interpolate_some から始め、その処理を ExtendedInterpolation._interpolate_some の処理と比較してください。値のないオプションのケースで TypeError が発生しなくなり、意図された補間動作に従うことを確認してください。リンクされた PR gh-153857 は、作業がすでに進行中であることを示しています。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100