python / python/cpython

ConfigParser.items() docstring does not describe the no-argument overload

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

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

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

説明

Documentation

The docstring of configparser.ConfigParser.items at Lib/configparser.py:887-897 describes only the call with a section argument:

def items(self, section=_UNSET, raw=False, vars=None):
    """Return a list of (name, value) tuples for each option in a section.

    All % interpolations are expanded in the return values, based on the
    defaults passed into the constructor, unless the optional argument
    `raw` is true.  Additional substitutions may be provided using the
    `vars` argument, which must be a dictionary whose contents overrides
    any pre-existing defaults.

    The section DEFAULT is special.
    """
    if section is _UNSET:
        return super().items()
    ...
    return [(option, value_getter(option)) for option in orig_keys]

When called with no arguments, items() delegates to the items() method inherited from collections.abc.Mapping and returns a collections.abc.ItemsView of (section_name, section_proxy) pairs — not a list of (name, value) tuples. The docstring currently mentions neither this overload nor its return type.

This is a follow-up to gh-149050 / gh-150059, which fixed the same kind of mismatch in Doc/library/configparser.rst. StanFromIreland reviewed that PR, while picnixz discussed the behavior on the issue. The .rst change remained scoped to the library documentation, so the docstring was left unchanged and is tracked here.

Suggested fix

Reword the docstring so that both overloads are described, e.g.:

"""Return the items of the parser or of a section.

When *section* is not given, return an :class:`~collections.abc.ItemsView`
of `(section_name, section_proxy)` pairs, including `DEFAULTSECT`.

Otherwise, return a list of `(name, value)` tuples for each option in the
given section.  All % interpolations are expanded in the return values,
based on the defaults passed into the constructor, unless the optional
argument `raw` is true.  Additional substitutions may be provided using
the `vars` argument, which must be a dictionary whose contents overrides
any pre-existing defaults.

The section DEFAULT is special.
"""

(bpo-15803 / gh-60007 corrected the module-level API summary in 2012. The no-argument overload itself was added in 2010, but this method docstring continued to describe only the section-argument form.)

Linked PRs
  • gh-150133

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

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

はじめの一歩

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

調査の方向性

Lib/configparser.py:887-897 から始め、ConfigParser.items() と継承した Mapping.items() の動作を比較してください。変更を加える前に、リンクされたドキュメントのフォローアップと gh-150133 を確認してください。引数なしの ItemsView 形式とセクション引数を指定したリスト形式の両方を docstring が正確に説明していれば完了です。

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

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
1/5
見積もり時間
1時間未満
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

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

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