python / python/cpython

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

Open
#150,132 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs stdlib
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

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 Lib/configparser.py:887-897 and compare ConfigParser.items() with the inherited Mapping.items() behavior. Check the linked documentation follow-up and gh-150133 before making changes. Done means the docstring describes both the no-argument ItemsView and section-argument list forms accurately.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.