Skip to content

gh-148325: Add PyObject_GetItemData() to the limited C API and stable ABI#148324

Open
wjakob wants to merge 1 commit intopython:mainfrom
wjakob:main
Open

gh-148325: Add PyObject_GetItemData() to the limited C API and stable ABI#148324
wjakob wants to merge 1 commit intopython:mainfrom
wjakob:main

Conversation

@wjakob
Copy link
Copy Markdown
Contributor

@wjakob wjakob commented Apr 10, 2026

This PR promotes PyObject_GetItemData() and PyObject_GetItemData_DuringGC() to the stable ABI (analogous to PyObject_GetTypeData() and PyObject_GetTypeData_DuringGC() that are already in the stable ABI).

The function PyObject_GetItemData() is needed to access the entries of variable sized objects (PyVarObject).

Why this change?

  • PyVarObject becomes opaque in abi3t.
  • nanobind (used by large-scale ML and compiler projects like Google's JAX, Apple's MLX, LLVM, MLIR, ...) uses a variable sized function object
  • Ergo: without access to PyObject_GetItemData(), nanobind cannot run on abi3t.

I am urgently (⚠️) trying to still get this into Python 3.15.

@vstinner @ngoldbaum @encukou


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

@wjakob wjakob requested review from a team, ZeroIntensity and encukou as code owners April 10, 2026 07:30
@wjakob wjakob changed the title gh-145921: Add PyObject_GetItemData to the limited C API and stable ABI gh-148325: Add PyObject_GetItemData to the limited C API and stable ABI Apr 10, 2026
…able ABI

Move PyObject_GetItemData and PyObject_GetItemData_DuringGC from the
unstable CPython API (Include/cpython/object.h) to the limited C API
(Include/object.h), gated on Py_LIMITED_API >= 3.15, and declare them
as part of the stable ABI in Misc/stable_abi.toml.
@wjakob wjakob changed the title gh-148325: Add PyObject_GetItemData to the limited C API and stable ABI gh-148325: Add PyObject_GetItemData() to the limited C API and stable ABI Apr 10, 2026
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

The function is documented and tested by test_capi.test_misc (HeapCCollection tests and test_pyobject_getitemdata_error()).

# Before 3.15, this was a macro that accessed the PyObject member
added = '3.15'
[function.PyObject_GetItemData]
# Before 3.15, this was only available in the unstable CPython API
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: I'm not sure that this comment is useful, it's the case for most functions added to the stable ABI.


.. versionadded:: 3.12

.. versionchanged:: 3.15
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
.. versionchanged:: 3.15
.. versionchanged:: next

@vstinner
Copy link
Copy Markdown
Member

I am urgently (⚠️) trying to still get this into Python 3.15.

Python 3.15 feature freeze will occur at 3.15.0 beta 1, Tuesday, 2026-05-05. It should be doable.

@vstinner
Copy link
Copy Markdown
Member

I created capi-workgroup/decisions#103 decision issue for the C API Working Group.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants