[issue40004] String comparison with dotted numerical values wrong

Boštjan Mejak report at bugs.python.org
Wed Mar 18 13:25:19 EDT 2020


New submission from Boštjan Mejak <bostjan.xperia at gmail.com>:

I stumbled upon a possible bug in the Python interpreter while doing some Python version comparisons.

Look at this:
"3.10.2" < "3.8.2"
True  # This is not true as a version number comparison

Now look at this:
"3.10.2" < "3.08.2"
False  # Adding a leading 0 compares those two version numbers correctly

Is it possible Python is fixed to correctly compare such numbers? That would make comparing Python version numbers possible in the future.

import platform
if platform.python_version() < "3.8.2":
    # Do something

This is currently possible and correct, but this will break when Python version number becomes 3.10 and you wanna compare this version number to, say, 3.9.

----------
components: Interpreter Core
messages: 364535
nosy: PedanticHacker, gvanrossum
priority: normal
severity: normal
status: open
title: String comparison with dotted numerical values wrong
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40004>
_______________________________________


More information about the Python-bugs-list mailing list