Docs: Use PY_VERSION_HEX for version comparison #100179
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.


PY_VERSION_HEXshould be used when comparing version numbers, for examplePY_VERSION_HEX >= 0x03080000.Avoid
PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8because that is true for 3.8-3.12, but also for 4.8-4.12 and so on.This is already warned in
patchlevel.hwherePY_VERSION_HEXis defined:cpython/Include/patchlevel.h
Lines 29 to 35 in 2e279e8
It's a bit hidden there, let's hoist it into docs in
apiabiversion.rstfor visibilty.Preview