Skip to content

Conversation

@gpshead
Copy link
Member

@gpshead gpshead commented Nov 17, 2025

Summary

Implement the TODO at line 99-100 in Modules/xxlimited.c to add Py_tp_token slot support, demonstrating Python 3.14 type checking best practices for Limited C API extension modules.

Changes

  • Update Limited API version from 3.13 to 3.14
  • Add Py_tp_token slot with Py_TP_USE_SPEC to Xxo_Type_slots
  • Add "Type Checking with Heap Types" section to isolating-extensions.rst

Rationale

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_token feature added in #124153.

Relates to #134160 (documentation modernization).


PR description written with Claude Code.


📚 Documentation preview 📚: https://cpython-previews--141644.org.readthedocs.build/

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]>
@gpshead gpshead added docs Documentation in the Doc dir needs backport to 3.14 bugs and security fixes labels Nov 17, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Nov 17, 2025
@gpshead gpshead requested a review from encukou November 17, 2025 00:45
@gpshead
Copy link
Member Author

gpshead commented Nov 17, 2025

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.

Copy link
Member

@encukou encukou left a 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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir needs backport to 3.14 bugs and security fixes skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants