Skip to content

fix tp_clear of subclass not being installed properly - #6315

Merged
Icxolu merged 1 commit into
PyO3:mainfrom
davidhewitt:subclass-clear
Aug 10, 2026
Merged

fix tp_clear of subclass not being installed properly#6315
Icxolu merged 1 commit into
PyO3:mainfrom
davidhewitt:subclass-clear

Conversation

@davidhewitt

Copy link
Copy Markdown
Member

This is a followup to #6269

When creating a subclass with a __clear__ implementation, the condition for base_is_gc() introduced in #6269 would incorrectly cause the synthesized_clear to replace the user-provided __clear__.

This PR fixes the condition to instead nest the if statements so that the !self.has_clear gates the whole block. I also tweaked the logic when delegating to the base clear so that instead of installing synthesized_clear which walks the MRO to discover the base clear, we just copy the base clear slot directly.

Credit to Codex security scanning for the discovery.

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Aug 10, 2026
@davidhewitt

Copy link
Copy Markdown
Member Author

Doesn't need a changelog entry because it's a correction to the unreleased #6269.

@Icxolu
Icxolu added this pull request to the merge queue Aug 10, 2026
Merged via the queue into PyO3:main with commit 693f003 Aug 10, 2026
50 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants