Skip to content

fix tp_clear of subclass not being installed properly - #6315

Open
davidhewitt wants to merge 1 commit into
PyO3:mainfrom
davidhewitt:subclass-clear
Open

fix tp_clear of subclass not being installed properly#6315
davidhewitt wants to merge 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.

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.

1 participant