Skip to content

Commit

Permalink
Use PY_VERSION_HEX for version comparison
Browse files Browse the repository at this point in the history
`PY_VERSION_HEX` should be used when comparing version numbers, for
example `PY_VERSION_HEX >= 0x03080000`.

Avoid `PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8` because
that is true for 3.8-3.12, but also for 4.8-4.12 and so on.

Hoist the comment from `PY_VERSION_HEX`'s definition in `patchlevel.h`
to docs in `apiabiversion.rst`.
  • Loading branch information
hugovk committed Dec 11, 2022
1 parent 2e279e8 commit 02a0eb0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Doc/c-api/apiabiversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
Thus ``3.4.1a2`` is hexversion ``0x030401a2`` and ``3.10.0`` is
hexversion ``0x030a00f0``.

Use this for numeric comparisons, e.g. ``#if PY_VERSION_HEX >= ...``

This version is also available via the symbol :data:`Py_Version`.

.. c:var:: const unsigned long Py_Version
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,7 @@ Porting to Python 3.11
can define the following macros and use them throughout
the code (credit: these were copied from the ``mypy`` codebase)::

#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8
#if PY_VERSION_HEX >= 0x03080000
# define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc)
# define CPy_TRASHCAN_END(op) Py_TRASHCAN_END
#else
Expand Down

0 comments on commit 02a0eb0

Please sign in to comment.