Skip to content

gh-158886: Add macros of the limited C API to stable_abi.toml - #158887

Open
vstinner wants to merge 9 commits into
python:mainfrom
vstinner:stable_macros
Open

vstinner wants to merge 9 commits into
python:mainfrom
vstinner:stable_macros

Conversation

@vstinner

@vstinner vstinner commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

@vstinner
vstinner requested a review from a team as a code owner October 5, 2026 22:37
@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

The Doctest job fails with:

sphinx.errors.SphinxParallelError: sphinx.errors.ExtensionError: Handler <function add_annotations at 0x7af8150d5fd0> for event 'doctree-read' threw an exception (exception: Object type mismatch in limited API annotation for PyObject_New: 'function' != 'macro')

I documented PyObject_New() as a function in stable_abi.toml ([function.PyObject_New]) to fix to fix Doctest, but it doesn't work as expected.

Problem: macros declared as functions by stable_abi.toml are checked by Lib/test/test_stable_abi_ctypes.py which fails since they are macros and not functions...

@vstinner
vstinner marked this pull request as draft October 5, 2026 22:44
@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

I updated the PR to document all macros as macros, not as functions.

@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

Updated Doctest error:

sphinx.errors.SphinxParallelError: sphinx.errors.ExtensionError: Handler <function add_annotations at 0x7353c3fd9fd0> for event 'doctree-read' threw an exception (exception: Object type mismatch in limited API annotation for PyImport_ImportModuleEx: 'macro' != 'function')

@read-the-docs-community

read-the-docs-community Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34957345 | 📁 Comparing 1db4cb9 against main (eab2d16)

  🔍 Preview build  

33 files changed · ± 33 modified

± Modified

@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

I updated Doc/tools/extensions/c_annotations.py to accept that some documented functions are defined as macros by stable_abi.toml.

@vstinner
vstinner marked this pull request as ready for review October 5, 2026 23:56
@encukou

encukou commented Oct 6, 2026

Copy link
Copy Markdown
Member

Could you limit this PR to the refcounting macros, and keep the issue open for the rest?
I don't think they should all be added at once.


One problem is that this annotates macros as “Part of the stable ABI”:

image

But, macros are not ABI.

We already have this issue with, for example, Py_BEGIN_ALLOW_THREADS, but there it's at least clear from the prose (or context) that it's a macro. Adding this to things documented as functions would be misleading.


For macros like Py_ULL or PyAPI_DATA, I think it would be better to treat them as exposed by mistake, rather than limited API. For ones like Py_IS_FINITE, we probably need more discussion (or not -- we can leave them in a gray area and focus on other stuff).

For macros like PyBytes_Check, IMO we should document the (approximate) expansion, so wrappers like PyO3 can reimplement them using just the stable ABI.

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