Skip to content

[configparser] Narrow RawConfigParser.popitem() to SectionProxy - #16289

Open
advitrocks9 wants to merge 1 commit into
python:mainfrom
advitrocks9:configparser-popitem-sectionproxy
Open

[configparser] Narrow RawConfigParser.popitem() to SectionProxy#16289
advitrocks9 wants to merge 1 commit into
python:mainfrom
advitrocks9:configparser-popitem-sectionproxy

Conversation

@advitrocks9

Copy link
Copy Markdown
Contributor

Follow-up to #16238, which left this one out.

RawConfigParser never declares popitem(), so it resolves to MutableMapping.popitem with _VT bound to _Section:

cp = configparser.ConfigParser()
cp.read_string("[a]\nx = 1\n")
name, section = cp.popitem()
section.name
error: "Mapping[str, str]" has no attribute "name"  [attr-defined]

At runtime RawConfigParser defines its own popitem, and it returns self[key], which __getitem__ already declares as SectionProxy. __getitem__, items() and values() are all narrowed the same way.

@github-actions

Copy link
Copy Markdown
Contributor

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

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.

1 participant