Skip to content

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

Merged
merged 2 commits into from
Sep 10, 2021
Merged

IDLE: adjust Python version in doc url for 3.10+ #28228

merged 2 commits into from
Sep 10, 2021

Conversation

giovanniwijaya
Copy link
Contributor

@giovanniwijaya giovanniwijaya commented Sep 8, 2021

Expression 'python_version()[:3]' truncated '3.10.0' to '3.1' instead of '3.10'.

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.
@terryjreedy terryjreedy changed the title Use sys.version_info to create idlelib docs link string [skip issue] [skip news] IDLE: Use sys.version_info to create url Sep 8, 2021
@terryjreedy
Copy link
Member

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.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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)

@terryjreedy terryjreedy changed the title IDLE: Use sys.version_info to create url IDLE: adjust version in doc url for 3.10+ Sep 10, 2021
@terryjreedy
Copy link
Member

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.

@terryjreedy
Copy link
Member

terryjreedy commented Sep 10, 2021

@ambv Merging is blocked because required Ubuntu test fails because unrelated test_ftplib alters execution environment.
https://github.com/python/cpython/pull/28228/checks?check_run_id=3563438190
This was reported a week ago bpo-44359.

1 test altered the execution environment:
    test_ftplib

10 tests skipped:
    test_devpoll test_ioctl test_kqueue test_msilib test_ossaudiodev
    test_startfile test_winconsoleio test_winreg test_winsound
    test_zipfile64

Total duration: 8 min 42 sec
Tests result: ENV CHANGED
make: *** [Makefile:1271: buildbottest] Error 3
Error: Process completed with exit code 2.

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.

@terryjreedy terryjreedy changed the title IDLE: adjust version in doc url for 3.10+ IDLE: adjust Python version in doc url for 3.10+ Sep 10, 2021
@terryjreedy terryjreedy merged commit b74c819 into python:main Sep 10, 2021
@miss-islington
Copy link
Contributor

Thanks @giovanniwijaya for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-28281 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Sep 10, 2021
@bedevere-bot
Copy link

GH-28282 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Sep 10, 2021
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 10, 2021
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]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 10, 2021
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]>
miss-islington added a commit that referenced this pull request Sep 10, 2021
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]>
terryjreedy pushed a commit that referenced this pull request Sep 10, 2021
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",
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

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:

  1. We haven't done that since and even in those releases sys.version_info included micro equal to 0.
  2. 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).
    """
  1. 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.

Copy link
Member

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.

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.

7 participants