gh-117482: Preserve the Mapping Between Type Slot Name and Attributes#122866
Closed
ericsnowcurrently wants to merge 2 commits intopython:mainfrom
Closed
gh-117482: Preserve the Mapping Between Type Slot Name and Attributes#122866ericsnowcurrently wants to merge 2 commits intopython:mainfrom
ericsnowcurrently wants to merge 2 commits intopython:mainfrom
Conversation
ericsnowcurrently
added a commit
that referenced
this pull request
Aug 12, 2024
…gh-122867) There were a still a number of gaps in the tests, including not looking at all the builtin types and not checking wrappers in subinterpreters that weren't in the main interpreter. This fixes all that. I considered incorporating the names of the PyTypeObject fields (a la gh-122866), but figured doing so doesn't add much value.
blhsing
pushed a commit
to blhsing/cpython
that referenced
this pull request
Aug 22, 2024
…orough (pythongh-122867) There were a still a number of gaps in the tests, including not looking at all the builtin types and not checking wrappers in subinterpreters that weren't in the main interpreter. This fixes all that. I considered incorporating the names of the PyTypeObject fields (a la pythongh-122866), but figured doing so doesn't add much value.
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.
In Objects/typeobject.c you'll find a static array named "slotdefs", which provides all the information needed to expose a type's "tp slots" (
PyTypeObjectfields) to Python code as "dunder" methods. The array is initialized using a bunch of macros that identify the tp slot and attribute name that go together. The array ends up holding that attribute name, but the slot name is not preserved currently. Having that mapping would be helpful for a test I've been working on (as well as various personal scripts I've been using).An alternative approach would be to have the macros actually preserve the slot name in each array item. That seems better than the after-the-fact way I've done it here. However, I tried modifying typeobject.c along those lines and it ended up being a bit messy. The approach here is less disruptive, so I've gone that route. Given that my current needs here are strictly related to tests, the testing-focused solution here should be fine.
(I may still circle back to the better approach later, to see if I can make it less disruptive.)
int.__str__behaviour inside sub-interpreters #117482