-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
IDLE: adjust Python version in doc url for 3.10+ #28228
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
Conversation
Hardcoding the python version in IDLE's "About IDLE" window to platform.python_version()[:3] truncates the Python version to 3.1 in Python 3.10 and above, as the minor version number is now 2 characters instead of 1. By using sys.version_info instead, the link will point to the right version regardless of number of characters in the major and minor version numbers.
Yes, the existing code is buggy in 3.10+. Thanks for catching this. I will consider whether this is the fix I prefer and perhaps rewrite to use string formatting or f-strings. Will then merge and backport. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general, but I suggest different formatting:
docs = Label(frame_background,
text='https://docs.python.org/%d.%d/library/idle.html' %
sys.version_info[:2],
justify=LEFT, fg=self.fg, bg=self.bg)
Imported function python_version was being called in 4 places and used as is in the other 3. After considering multiple options, I decided to call it once and end the slice at the second (last) '.'. This will work unless we change the versioning system. I prefer f-strings to .format and even more so to both % fomatting and multiple runtime string additions. We often convert when editing such code. |
@ambv Merging is blocked because required Ubuntu test fails because unrelated test_ftplib alters execution environment.
I will rerun and see what happens. This will of course, rerun tests that passed, putting them at risk of randomly failing and blocking merging. |
Thanks @giovanniwijaya for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
GH-28281 is a backport of this pull request to the 3.10 branch. |
GH-28282 is a backport of this pull request to the 3.9 branch. |
Expression 'python_version()[:3]' truncated '3.10.0' to '3.1' instead of '3.10'. Co-authored-by: Terry Jan Reedy <[email protected]> (cherry picked from commit b74c819) Co-authored-by: giovanniwijaya <[email protected]>
Expression 'python_version()[:3]' truncated '3.10.0' to '3.1' instead of '3.10'. Co-authored-by: Terry Jan Reedy <[email protected]> (cherry picked from commit b74c819) Co-authored-by: giovanniwijaya <[email protected]>
Expression 'python_version()[:3]' truncated '3.10.0' to '3.1' instead of '3.10'. Co-authored-by: Terry Jan Reedy <[email protected]> (cherry picked from commit b74c819) Co-authored-by: giovanniwijaya <[email protected]>
Expression 'python_version()[:3]' truncated '3.10.0' to '3.1' instead of '3.10'. Co-authored-by: Terry Jan Reedy <[email protected]> (cherry picked from commit b74c819) Co-authored-by: giovanniwijaya <[email protected]>
docs = Label(frame_background, text='https://docs.python.org/' + | ||
python_version()[:3] + '/library/idle.html', | ||
docs = Label(frame_background, text="https://docs.python.org/" | ||
f"{version[:version.rindex('.')]}/library/idle.html", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not guaranteed that the Python version contains exactly 2 dots. This code will not work with versions containing 1 or 3 dots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also Lib/idlelib/editor.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not guaranteed that the Python version contains exactly 2 dots.
Can you give an example where that's not the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.2
? Also we can release a micro-bugfix in future, like 3.11.2.1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, TIL that 2.7 and 3.2 were indeed missing the micro version in their initial releases. However:
- We haven't done that since and even in those releases
sys.version_info
includedmicro
equal to0
. - The code in this PR uses
platform.python_version
which is specifically documented like this:
""" Returns the Python version as string 'major.minor.patchlevel'
Note that unlike the Python sys.version, the returned value
will always include the patchlevel (it defaults to 0).
"""
- We actually literally cannot release versions with a fourth component because no downstream tooling expects that. If we need to recall a version due to a big issue, we simply bump the third number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. But all other code uses sys.version_info[:2]
instead of parsing platform.python_version()
if it needs a 2-component version. I think it is more reliable.
Expression 'python_version()[:3]' truncated '3.10.0' to '3.1' instead of '3.10'.