Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-138342: Use a common utility for visiting an object's type#138343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
ZeroIntensity commented Sep 1, 2025 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
Also use it in _bz2.
picnixz left a comment • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be smarter here:
- Let's first add your utility without it being used.
- Remove the traverse & GC support for types that are immutable and empty.
- Add the necessary traverse functions for objects whose class is meant to be mutable.
(1) can be achieved independently but (2) and (3) should perhaps be coordinated depending on what we want to backport. I would suggest that we don't change immutability in 3.13 and 3.14 (so we need the traverse functions for those types) but we can do in 3.15 (in which case we won't need this helper).
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
picnixz commented Sep 1, 2025
Nevermind, my comment got cross-posted with #116946 (comment). So apparently, it would be safer to not change the immutability of those types for now. |
ZeroIntensity commented Sep 1, 2025
Yeah, I found a few other types that don't need this. But as I said in the PR description:
This PR is pretty big already, and I would like to avoid sprinkling in behavior changes. Once your work with #116946 is done, we can strengthen the assertions in |
picnixz left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the changes that I will revert in #138338 are removed from this PR, we can merge this. Do you want to review it?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Adam Turner <[email protected]>
4f6ecd1 into python:mainUh oh!
There was an error while loading. Please reload this page.
kumaraditya303 commented Sep 3, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Most of these are cases where the object actually doesn't needs to have GC at all, they are empty objects with immutable types. Instead of adding this why not just remove GC from them? It will help in performance and reduce gc pressure. Also in future when improving the assertions, how would you check for empty objects? |
ZeroIntensity commented Sep 3, 2025
Something like |
…ythonGH-138343) Add `_PyObject_VisitType` in place of `tp_traverse` functions that only visit the object's type.
sergey-miryanov commented Sep 11, 2025
Also, I want to work on this. |
vstinner commented Oct 7, 2025
Unless there is a good reason to add this private function to the public C API, I would prefer to move it to the internal C API: see my PR #139734. If tomorrow, this function becomes popular and very useful outside CPython, I would suggest to make it public. But for now, I would prefer to keep it in the internal C API. |
ZeroIntensity commented Oct 7, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I kept it in public headers here to avoid adding |
vstinner commented Oct 8, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Later, it's easy to make it public: add it again to the public C API as |
Add
_PyObject_VisitTypein place oftp_traversefunctions that only visit the object's type. This will likely help us catch some bugs through assertions, as we can ensure that this only applies to mutable heap types (and thus are subject to reference cycles). For now, I've kept the assertions relatively relaxed to make it easier to review, but I'll strengthen those assertions and address any bugs in a follow-up.Sorry about the flood of pings, codeowners.