Skip to content

[configparser] Narrow RawConfigParser.values() to SectionProxy - #16238

Merged
srittau merged 1 commit into
python:mainfrom
advitrocks9:configparser-values-sectionproxy
Aug 20, 2026
Merged

[configparser] Narrow RawConfigParser.values() to SectionProxy#16238
srittau merged 1 commit into
python:mainfrom
advitrocks9:configparser-values-sectionproxy

Conversation

@advitrocks9

Copy link
Copy Markdown
Contributor

Closes: #11547

RawConfigParser already narrows __getitem__ and items() to SectionProxy but never declared
values(), so it falls through to Mapping.values with _VT_co bound to _Section.

Deriving the class from MutableMapping[str, SectionProxy] instead would regress code that checks
clean today:

error: Dict entry 0 has incompatible type "str": "dict[str, str]"; expected "str": "SectionProxy"  [dict-item]
error: Argument 2 to "setdefault" of "MutableMapping" has incompatible type "dict[str, str]"; expected "SectionProxy"  [arg-type]

on cp.update({"a": {"x": "1"}}) and cp.setdefault("b", {"y": "2"}), both of which work at
runtime. _Parser is also the declared parameter type of the four Interpolation hooks, so
narrowing it breaks third-party subclasses.

popitem() has the same gap and is narrowable on its own, so I left it for a separate PR.
setdefault() isn't: it returns the caller's own object, not the proxy it stored.

Assisted by Claude Code.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau
srittau merged commit 6e50bb7 into python:main Aug 20, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

configparser.ConfigParser.values() should return a ValuesView[configparser.SectionProxy]

2 participants