This has now been corrected, as a follow-up to this question. See issue #560, pull request #1123 and the summary of changes in the updated PEP:
- The definition of python_version was changed from
platform.python_version()[:3]
to '.'.join(platform.python_version_tuple()[:2]
, to accommodate potential future versions of Python with 2-digit major and minor versions (e.g. 3.10). [7]
The packaging
library source code has followed suit.
Original answer
I'm sure it is just an oversight or simplification for documentation purposes. The intention is clearly to provide a major.minor
version string.
Note that historically, there never has been a minor version number with double digits. So far, Python has managed with just one digit, always. The highest numbers, so far, have been 1.6
, 2.7
and 3.7
. That's not to say there never will be a 3.10
in future, but so far, it just hasn't come up.
I'd imagine an actual implementation to use platform.python_version_tuple()
:
return '.'.join(platform.python_version_tuple()[:2]
or
major, minor, patch = platform.python_version_tuple()
return '{}.{}'.format(major, minor)
However, both forms are rather a bit more verbose to fit into a PEP table column aiming to document rather than prescribe code.
If in doubt, write to the Python-dev mailing list. I'm sure that if this was to become so confusing as to be problematic, the PEP can be adjusted.
As for pip; it uses the vendored packaging
library to handle environment markers, which has implemented the python_version
marker verbatim as specced in the PEP. If you feel strongly about it, you could file an issue there, the PEP maintainers are active on that project.
Note that there is still plenty of time. So far, 3.x releases each take about 18 months to appear (3.2: 2011-02, 3.3: 2012-09, 3.4: 2014-03, 3.5: 2015-09, 3.6: 2016-12, 3.7: expected 2018-06), so we have 5 years or so to address this.