-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-124153: Add Py_tp_token support to xxlimited module #141644
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
base: main
Are you sure you want to change the base?
Conversation
Implement the TODO at line 99-100 to add Py_tp_token slot support, demonstrating Python 3.14 type checking best practices for Limited C API extension modules. Changes to Modules/xxlimited.c: - Update Limited API version from 3.13 (0x030d0000) to 3.14 (0x030e0000) - Add Py_tp_token slot with Py_TP_USE_SPEC to Xxo_Type_slots Changes to Doc/howto/isolating-extensions.rst: - Add new "Type Checking with Heap Types" section documenting Py_tp_token - Reference xxlimited.c as example and link to pythongh-124153 This addresses the type-checking problem for heap types described in PEP 630 and aligns with the documentation modernization effort (pythongh-134160). The xxlimited module now serves as a complete example of modern isolated extension module development. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
I guess my question about this is... should we recommend people always do this? is there a downside worth mentioning? cc @neonene as well as the original author of the 3.14 feature PR. |
encukou
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.
Thanks for adding this!
should we recommend people always do this
IMO, no -- they should only do it if they need the token (e.g. for XxoObject_Check). Ideally, this should be a tool that's there if you need it, not “best practice” to be cargo-culted in every definition.
But, on the other hand, it's not easy to document it that way. So, maybe suggesting that people should do it, and putting it in the copy-pastable example is the right way.
But then people might wonder why Python doesn't do this automatically...
| #include "pyconfig.h" // Py_GIL_DISABLED | ||
| #ifndef Py_GIL_DISABLED | ||
| # define Py_LIMITED_API 0x030d0000 | ||
| # define Py_LIMITED_API 0x030e0000 |
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.
What do you think about copying the original to xxlimited_3_13.c, so we have an example for older stable ABI?
|
#142827 adds a After/if that's merged, I plan to adapt the HOWTO addition from this PR after that. And ideally add an actual example of type-checking :) |
Summary
Implement the TODO at line 99-100 in
Modules/xxlimited.cto addPy_tp_tokenslot support, demonstrating Python 3.14 type checking best practices for Limited C API extension modules.Changes
Py_tp_tokenslot withPy_TP_USE_SPECtoXxo_Type_slotsRationale
This addresses the type-checking problem for heap types described in PEP 630. The xxlimited module serves as a template for extension developers, and this change demonstrates modern Python 3.14 type-checking best practices using the
Py_tp_tokenfeature added in #124153.Relates to #134160 (documentation modernization).
PR description written with Claude Code.
PyType_GetBaseByTokenfunction withPy_tp_tokenslot #124153📚 Documentation preview 📚: https://cpython-previews--141644.org.readthedocs.build/