Skip to content

Commit 2a3dfe0

Browse files
authored
PEP 2026: Note PY_VERSION_HEX changes needed for 3.YYYY (#3995)
1 parent 9c9c5c3 commit 2a3dfe0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

peps/pep-2026.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,24 @@ However, YY.MM versioning is rejected for many of the same reasons as YY.0 versi
532532
For example, Python 3.2026 would be released in 2026.
533533

534534
It's clearer that the minor version is a year when using a four digits, and
535-
avoids confusion with Ubuntu versions which use YY.MM. However, this is
536-
rejected as changing from two to four digits would break more code than 3.YY versioning.
535+
avoids confusion with Ubuntu versions which use YY.MM.
536+
537+
``PY_VERSION_HEX``
538+
''''''''''''''''''
539+
540+
CPython's C API :external+python:c:macro:`PY_VERSION_HEX` macro currently uses
541+
eight bits to encode the minor version, accommodating a maximum minor version of
542+
255. To hold a four-digit year, it would need to be expanded to 11 bits to fit
543+
2047 or rather 12 bits for 4095.
544+
545+
This looks feasible, as it's intended for numeric comparisons, such as
546+
``#if PY_VERSION_HEX >= ...``. In the `top 8,000 PyPI projects
547+
<https://dev.to/hugovk/how-to-search-5000-python-projects-31gk>`__
548+
only one instance was found of bit shifting
549+
(``hexversion >> 16 != PY_VERSION_HEX >> 16``).
550+
551+
However, 3.YYYY is rejected as changing from two to four digits would
552+
nevertheless need more work and break more code than simpler 3.YY versioning.
537553

538554
Editions
539555
--------

0 commit comments

Comments
 (0)