Skip to content

gh-161108: Make configparser clear() linear time - #161109

Merged
gpshead merged 1 commit into
python:mainfrom
gpshead:configparser-clear-quadratic
Nov 1, 2026
Merged

gpshead merged 1 commit into
python:mainfrom
gpshead:configparser-clear-quadratic

Conversation

@gpshead

@gpshead gpshead commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Give SectionProxy its own popitem() and clear(), and RawConfigParser its own clear(), so they take the keys from the underlying dicts once instead of copying every remaining key on each removal. RawConfigParser.clear() still goes through del self[section], so subclass __delitem__() overrides keep running. This also fixes two oddities of the inherited MutableMapping methods: section.clear() no longer fails part way with InterpolationError on a value it is removing, and section.popitem() on a section with only DEFAULT options left raises KeyError without naming a DEFAULT option it could not remove.

Fixes #161108

ANT-2026-FWT5DX83

Give SectionProxy its own popitem() and clear() and RawConfigParser its
own clear() instead of the MutableMapping ones, which copied every
remaining key for each removal.
@gpshead gpshead added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 1, 2026
@gpshead gpshead self-assigned this Nov 1, 2026
@gpshead
gpshead marked this pull request as ready for review November 1, 2026 18:29
@gpshead
gpshead requested a review from jaraco as a code owner November 1, 2026 18:29
@gpshead
gpshead enabled auto-merge (squash) November 1, 2026 18:29
@gpshead
gpshead merged commit 2a1282b into python:main Nov 1, 2026
62 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161133 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 1, 2026
@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161134 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 1, 2026
gpshead added a commit that referenced this pull request Nov 1, 2026
…161133)

Give SectionProxy its own popitem() and clear() and RawConfigParser its
own clear() instead of the MutableMapping ones, which copied every
remaining key for each removal.

#161109
(cherry picked from commit 2a1282b)
gpshead added a commit that referenced this pull request Nov 1, 2026
…161134)

Give SectionProxy its own popitem() and clear() and RawConfigParser its
own clear() instead of the MutableMapping ones, which copied every
remaining key for each removal.

#161109
(cherry picked from commit 2a1282b)
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 clear() on a section or parser takes quadratic time

1 participant