Skip to content

feat(ffi): add Python 3.14 context watcher API#6204

Open
florentinl wants to merge 4 commits into
PyO3:mainfrom
florentinl:agent/python-314-context-watcher
Open

feat(ffi): add Python 3.14 context watcher API#6204
florentinl wants to merge 4 commits into
PyO3:mainfrom
florentinl:agent/python-314-context-watcher

Conversation

@florentinl

@florentinl florentinl commented Jul 15, 2026

Copy link
Copy Markdown

Python 3.14 added a context watcher API for observing contextvars.Context switches.

This exposes the raw declarations in pyo3-ffi.

Relevant links:

@florentinl florentinl force-pushed the agent/python-314-context-watcher branch from 6535a6a to 5c25a54 Compare July 15, 2026 11:40
@florentinl florentinl marked this pull request as ready for review July 15, 2026 12:07
@bschoenmaeckers

Copy link
Copy Markdown
Member

This file should be moved to the cpython folder. To mirror upstream.

@florentinl

florentinl commented Jul 15, 2026

Copy link
Copy Markdown
Author

This makes sense to me. Should i do it in this PR ? Or move it in a prior PR and then add the watcher API ?

@bschoenmaeckers

bschoenmaeckers commented Jul 15, 2026

Copy link
Copy Markdown
Member

This makes sense to me. Should i do it in this PR ? Or move it in a prior PR and then add the watcher API ?

Yes please, you can do it here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed420e5f6f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pyo3-ffi/src/cpython/mod.rs
@florentinl

florentinl commented Jul 15, 2026

Copy link
Copy Markdown
Author

The RustPython bindings still need to stay outside of the cpython module which is marked with #[cfg(not(any(Py_LIMITED_API, RustPython)))]. So I kept the previous context.rs just for RustPython for this reason.

Is this the correct approach in these cases ?

@bschoenmaeckers

Copy link
Copy Markdown
Member

The RustPython bindings still need to stay outside of the cpython module which is marked with #[cfg(not(any(Py_LIMITED_API, RustPython)))]. So I kept the previous context.rs just for RustPython for this reason.

Is this the correct approach in these cases ?

RustPython only supports abi3/abi3t so these functions are not exposed. So you can remove all RustPython cfg attributes.

Comment thread pyo3-ffi/src/lib.rs Outdated
@florentinl florentinl force-pushed the agent/python-314-context-watcher branch from da0c232 to 454b758 Compare July 15, 2026 15:23
@bschoenmaeckers

Copy link
Copy Markdown
Member

Thanks! LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants