Skip to content

perf: add __slots__ to Requirement - #1320

Merged
henryiii merged 1 commit into
pypa:mainfrom
henryiii:henryiii/perf/req-slots
Jul 7, 2026
Merged

perf: add __slots__ to Requirement#1320
henryiii merged 1 commit into
pypa:mainfrom
henryiii:henryiii/perf/req-slots

Conversation

@henryiii

@henryiii henryiii commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Looking at #1252, the first step toward making these immutable is adding slots. This is the only remaining one missing one of the major classes that would benefit (not counting dataclasses).

🤖 AI text below 🤖

Adds __slots__ to Requirement, matching Version, Specifier, SpecifierSet, Marker, and Tag.

The legacy-pickle branch in __setstate__ (for pickles from packaging <= 26.1, which stored a plain __dict__) now restores attributes via setattr, since slotted instances have no __dict__. The existing tests that load real pickle bytes from packaging 25.0/26.0/26.1 cover that path; a new test asserts instances have no __dict__.

Adapt the legacy-pickle branch in __setstate__ to restore attributes via
setattr, since slotted instances have no __dict__.

Assisted-by: ClaudeCode:claude-fable-5
@henryiii
henryiii marked this pull request as ready for review July 7, 2026 16:36
@henryiii
henryiii merged commit d5fedc9 into pypa:main Jul 7, 2026
69 checks passed
@henryiii
henryiii deleted the henryiii/perf/req-slots branch July 7, 2026 23:45
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.

2 participants