Use PEP-697 interface to access stashed data in type objects #211
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 commit currently fails because the CI still builds against Python 3.12a7 that doesn't yet have PEP697. It will be merged once the GHA setup-python action has caught up with 3.12 beta
PEP 697 introduced a new limited C API to extend opaque types. nanobind needs this feature because it stashes internal type data structures within Python
type
objects. Previously, we assumed a standard Python memory layout for such opaque types and did not do anything special besides adding an offset to get to the nanobind part.However, such an approach is not acceptable when using nanobind to compile future-proof stable ABI wheels: the Python team may at some point significantly refactor the layout and internals of
type
objects, which would lead to undefined behavior in combination with our assumptions. This commit therefore switches to the recently introduced official interface that ensures long-term stability.