Visitar URL original
Docs: Use PY_VERSION_HEX for version comparison by hugovk · Pull Request #100179 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221214075420/https://github.com/python/cpython/pull/100179
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Use PY_VERSION_HEX for version comparison #100179

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Dec 11, 2022 •

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.

This is already warned in patchlevel.h where PY_VERSION_HEX is defined:

/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */
#define PY_VERSION_HEX ((PY_MAJOR_VERSION << 24) | \
(PY_MINOR_VERSION << 16) | \
(PY_MICRO_VERSION << 8) | \
(PY_RELEASE_LEVEL << 4) | \
(PY_RELEASE_SERIAL << 0))

It's a bit hidden there, let's hoist it into docs in apiabiversion.rst for visibilty.

Preview

`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`.
@netlify
Copy link

netlify bot commented Dec 11, 2022 •

✅ Deploy Preview for python-cpython-preview ready!

Name Link
🔨 Latest commit 52763bb
🔍 Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/6396b9259cefee0008627c46
😎 Deploy Preview https://deploy-preview-100179--python-cpython-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Doc/c-api/apiabiversion.rst Outdated Show resolved Hide resolved
Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
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.

None yet

3 participants