GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-124153: Add Py_tp_token support to xxlimited module by gpshead · Pull Request #141644 · python/cpython

Conversation

@gpshead

@gpshead gpshead commented Nov 17, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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: Add PyType_GetBaseByToken function with Py_tp_token slot #124153

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@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 added this to Docs PRs Nov 17, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Nov 17, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 17, 2025
Add PyType_GetBaseByToken function with Py_tp_token slot #124153
Closed
6 tasks done
@gpshead gpshead added the skip news label Nov 17, 2025
@gpshead
gpshead requested a review from encukou November 17, 2025 00:45
@gpshead

gpshead commented Nov 17, 2025

Copy link
Copy Markdown
Member Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou
encukou reviewed Nov 17, 2025
View reviewed changes

@encukou encukou left a comment

Copy link
Copy Markdown
Member

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...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/xxlimited.c Outdated
#include "pyconfig.h" // Py_GIL_DISABLED
#ifndef Py_GIL_DISABLED
# define Py_LIMITED_API 0x030d0000
# define Py_LIMITED_API 0x030e0000

@encukou encukou Nov 17, 2025

Copy link
Copy Markdown
Member

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@encukou

encukou commented Dec 16, 2025

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 2, 2026
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 bugs and security fixes label May 30, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 2, 2026
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 4, 2026
@gpshead @claude @ambv
Add Py_tp_token support to xxlimited module
70d23e1
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]>
@ambv
ambv force-pushed the xxlimited-tp-token branch from 93b525f to 70d23e1 Compare October 20, 2026 21:19
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 20, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 20, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35281579 | 📁 Comparing 70d23e1 against main (39bc958)

  🔍 Preview build  

1 file changed
± howto/isolating-extensions.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes skip news type-feature A feature request or enhancement

Projects

Docs PRs
Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@gpshead @encukou @serhiy-storchaka
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.