Skip to content

PEP 813: guard PyObject_Pretty() by limited API version - #7

Open
warsaw wants to merge 1 commit into
ericvsmith:PEP-813-pprintfrom
warsaw:pep813-limited-api-guard
Open

warsaw wants to merge 1 commit into
ericvsmith:PEP-813-pprintfrom
warsaw:pep813-limited-api-guard

Conversation

@warsaw

@warsaw warsaw commented Oct 24, 2026

Copy link
Copy Markdown

PyObject_Pretty() is registered in Misc/stable_abi.toml as added in 3.16, and the generated stable ABI files include it, but its declaration in Include/object.h had no version guard. An extension built against an older limited API, such as Py_LIMITED_API=0x030a0000, could compile against it and then fail to load on Python 3.10 through 3.15.

This wraps the declaration in #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000, as with other limited API additions. make check-limited-abi doesn't check these guards, which is why it passed before.

Checked with the compiler: with Py_LIMITED_API=0x030a0000 the function is undeclared, and with 0x03100000 or the full API it's visible. make check-limited-abi, test_stable_abi_ctypes, test_capi, test_fstring and test_tstring pass.

🤖 Generated with Claude Code

PyObject_Pretty() is part of the limited API from 3.16, but it was
declared without a version guard.  An extension built against an older
limited API, such as Py_LIMITED_API=0x030a0000, could compile against it
and then fail to load on Python 3.10 through 3.15.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant