From d8d0bde09fcb9c303db7d2b668fbded403e9a1b5 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 9 Jan 2026 12:42:51 +0100 Subject: [PATCH 1/2] gh-141004: Document all constants of patchlevel.h --- Doc/c-api/apiabiversion.rst | 21 +++++++++++++++++++++ Doc/c-api/module.rst | 7 +++++-- Tools/check-c-api-docs/ignored_c_api.txt | 8 -------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Doc/c-api/apiabiversion.rst b/Doc/c-api/apiabiversion.rst index 96050f59bd5250..a17329e4ed6032 100644 --- a/Doc/c-api/apiabiversion.rst +++ b/Doc/c-api/apiabiversion.rst @@ -34,6 +34,23 @@ See :ref:`stable` for a discussion of API and ABI stability across versions. This can be ``0xA`` for alpha, ``0xB`` for beta, ``0xC`` for release candidate or ``0xF`` for final. + + .. c:namespace:: NULL + .. c:macro:: PY_RELEASE_LEVEL_ALPHA + :no-typesetting: + .. c:macro:: PY_RELEASE_LEVEL_BETA + :no-typesetting: + .. c:macro:: PY_RELEASE_LEVEL_GAMMA + :no-typesetting: + .. c:macro:: PY_RELEASE_LEVEL_FINAL + :no-typesetting: + + For completeness, the values are available as macros: + :c:macro:`!PY_RELEASE_LEVEL_ALPHA` (``0xA``), + :c:macro:`!PY_RELEASE_LEVEL_BETA` (``0xB``), + :c:macro:`!PY_RELEASE_LEVEL_GAMMA` (``0xC``), and + :c:macro:`!PY_RELEASE_LEVEL_FINAL` (``0xF``). + .. c:macro:: PY_RELEASE_SERIAL The ``2`` in ``3.4.1a2``. Zero for final releases. @@ -46,6 +63,10 @@ See :ref:`stable` for a discussion of API and ABI stability across versions. Use this for numeric comparisons, for example, ``#if PY_VERSION_HEX >= ...``. +.. c:macro:: PY_VERSION + + The Python version as a string, for example, ``"3.4.1a2"``. + Run-time version ---------------- diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index 37c92aeb6dcb38..5c108903450966 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -820,15 +820,18 @@ struct: .. versionadded:: 3.5 .. c:macro:: PYTHON_API_VERSION + PYTHON_API_STRING - The C API version. Defined for backwards compatibility. + The C API version, as an integer (``1013``) and string (``"1013"``). + Defined for backwards compatibility. Currently, this constant is not updated in new Python versions, and is not useful for versioning. This may change in the future. .. c:macro:: PYTHON_ABI_VERSION + PYTHON_ABI_STRING - Defined as ``3`` for backwards compatibility. + Defined as ``3`` and ``"3"``, respectively, for backwards compatibility. Currently, this constant is not updated in new Python versions, and is not useful for versioning. This may change in the future. diff --git a/Tools/check-c-api-docs/ignored_c_api.txt b/Tools/check-c-api-docs/ignored_c_api.txt index e0b94edf748853..31c920555992bb 100644 --- a/Tools/check-c-api-docs/ignored_c_api.txt +++ b/Tools/check-c-api-docs/ignored_c_api.txt @@ -58,14 +58,6 @@ PY_SIZE_MAX PY_UINT32_T PY_UINT64_T PY_ULLONG_MAX -# patchlevel.h -PYTHON_ABI_STRING -PYTHON_API_STRING -PY_RELEASE_LEVEL_ALPHA -PY_RELEASE_LEVEL_BETA -PY_RELEASE_LEVEL_FINAL -PY_RELEASE_LEVEL_GAMMA -PY_VERSION # unicodeobject.h Py_UNICODE_SIZE # cpython/methodobject.h From c6870695fee55b4211f0f2009523a0362c3fa05d Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 9 Jan 2026 18:14:08 +0100 Subject: [PATCH 2/2] Update Doc/c-api/module.rst Co-authored-by: Victor Stinner --- Doc/c-api/module.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index 5c108903450966..431151b841ebb6 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -822,7 +822,7 @@ struct: .. c:macro:: PYTHON_API_VERSION PYTHON_API_STRING - The C API version, as an integer (``1013``) and string (``"1013"``). + The C API version, as an integer (``1013``) and string (``"1013"``), respectively. Defined for backwards compatibility. Currently, this constant is not updated in new Python versions, and is not