cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-124153: Add Py_tp_token support to xxlimited module

Open gpshead opened this issue 2 months ago • 2 comments

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.

  • Issue: gh-124153

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

gpshead avatar Nov 17 '25 00:11 gpshead

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.

gpshead avatar Nov 17 '25 00:11 gpshead

https://github.com/python/cpython/pull/142827 adds a Xxo_state_from_type function and several examples of getting state->Xxo_Type from that. It also removes the TODO.

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 :)

encukou avatar Dec 16 '25 14:12 encukou