Skip to content

gh-149050: Fix return type of ConfigParser.items() in documentation#150059

Open
Taeknology wants to merge 1 commit into
python:mainfrom
Taeknology:gh-149050-document-configparser-items-itemsview
Open

gh-149050: Fix return type of ConfigParser.items() in documentation#150059
Taeknology wants to merge 1 commit into
python:mainfrom
Taeknology:gh-149050-document-configparser-items-itemsview

Conversation

@Taeknology
Copy link
Copy Markdown

@Taeknology Taeknology commented May 19, 2026

When ConfigParser.items() is called without a section argument, the
implementation delegates to super().items() (i.e. dict.items()) and
returns a collections.abc.ItemsView, not a list. The docs previously
described both overloads as returning a list, which is only correct
for the second overload (with a section argument).

This PR adjusts the first paragraph of the items() documentation in
Doc/library/configparser.rst to say ItemsView instead of list.
The second paragraph (with-section overload) is unchanged because
that one really does return a list.

Verified locally (against Lib/configparser.py on main)

I isolated cpython/Lib/configparser.py from the working tree and
loaded it with importlib.util to confirm the behaviour on current
main (not just the installed interpreter):

import importlib.util
spec = importlib.util.spec_from_file_location(
    "cpy_configparser",
    "/path/to/cpython/Lib/configparser.py",
)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)

cp = mod.ConfigParser()
cp.read_string("[sec]\nkey=val")
print(type(cp.items()).__name__)        # ItemsView
print(type(cp.items("sec")).__name__)   # list

Result:

no_arg type:  collections.abc.ItemsView
with_arg type: builtins.list
no_arg is collections.abc.ItemsView? True
with_arg is list? True

git log -L:'def items':Lib/configparser.py shows the body of
items() has not been touched since 199507b81a (a docstring-only
rst-markup fix), so this is a long-standing docs/behaviour mismatch
rather than a recent regression.

No code change. No Misc/NEWS.d entry (docs-only).

Fixes #149050

…tion

When called without a section argument, ConfigParser.items() delegates
to dict.items() and returns a collections.abc.ItemsView, not a list.
The docs previously described both overloads as returning a list.
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32752204 | 📁 Comparing 63dd638 against main (517d3d2)

  🔍 Preview build  

1 file changed
± library/configparser.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Note that configparser.ConfigParser.items returns a collections.abc.ItemsView in the first overload

1 participant