Skip to content
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

gh-117482: Preserve the Mapping Between Type Slot Name and Attributes #122866

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Aug 9, 2024

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" (PyTypeObject fields) 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.)

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.
@ericsnowcurrently ericsnowcurrently deleted the preserve-tp-slot-names-for-testing branch August 13, 2024 17:10
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant