always implement tp_traverse to traverse type object - #6269
Open
davidhewitt wants to merge 9 commits into
Open
Conversation
davidhewitt
marked this pull request as draft
July 31, 2026 10:02
davidhewitt
marked this pull request as ready for review
July 31, 2026 10:51
This was referenced Jul 31, 2026
Draft
Icxolu
reviewed
Jul 31, 2026
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
Icxolu
approved these changes
Jul 31, 2026
| ); | ||
| } | ||
|
|
||
| pub const fn assert_type_implements_traverse(implements_traverse: bool) { |
Member
There was a problem hiding this comment.
If we apply a #[track_caller] to this, it might clean up the error backtrace a bit.
Member
Author
There was a problem hiding this comment.
Good idea, pushed that and will merge, thanks!
davidhewitt
enabled auto-merge
July 31, 2026 20:20
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jul 31, 2026
davidhewitt
enabled auto-merge
August 1, 2026 06:36
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Aug 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a followup to #6206 which I noticed while reviewing (also very similar to #6224).
Reading the CPython docs for
tp_traverse:All
#[pyclass]types are heap types, but we were not doing that. The test added demonstrates a memory leak present onmainwhich this branch fixes.Summary of changes:
tp_traversewhich traverses the heap typecreate_type_objecttotp_dealloc/tp_dealloc_with_gcimplementations__clear__requires a__traverse__implementation to compile-time in macro code (with a UI test)PyVisittype implementation slightly at the same time