Skip to content
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

bpo-43284: Update platform.win32_ver to use platform._syscmd_ver instead of sys.getwindowsversion().platform_version for determining accurate Windows version #25500

Merged
merged 12 commits into from Apr 22, 2021

Conversation

shreyanavigyan
Copy link
Contributor

@shreyanavigyan shreyanavigyan commented Apr 21, 2021

platform.win32_ver derives the Windows version from sys.getwindowsversion().platform_version which in turn derives the version from kernel32.dll (which can be of a different version than Windows itself). Therefore this PR updates the platform.win32_ver to determine the version using the platform module's _syscmd_ver private function to return an accurate version.

More discussions are held at: https://bugs.python.org/issue43284

https://bugs.python.org/issue43284

Lib/platform.py Outdated Show resolved Hide resolved
Co-authored-by: Eryk Sun <eryksun@gmail.com>
@zooba
Copy link
Member

@zooba zooba commented Apr 21, 2021

I also noticed that _norm_version has a bug that is back in the code path with this change:

    try:
        ints = map(int, l)
    except ValueError:
        strings = l
    else:
        strings = list(map(str, ints))

The ValueError is never going to be raised there because map is lazy. We probably just want to merge the else block into the try: strings = list(map(str, map(int, l)))

@shreyanavigyan
Copy link
Contributor Author

@shreyanavigyan shreyanavigyan commented Apr 21, 2021

Are you suggesting to make the change in this PR itself?

@zooba
Copy link
Member

@zooba zooba commented Apr 21, 2021

Yes, please. (They don't exist, but any tests for these cases would be breaking on your PR because you've reintroduced the call to that function.)

@shreyanavigyan
Copy link
Contributor Author

@shreyanavigyan shreyanavigyan commented Apr 21, 2021

Change applied.

Lib/platform.py Outdated Show resolved Hide resolved
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
@shreyanavigyan shreyanavigyan requested a review from zooba Apr 21, 2021
@shreyanavigyan
Copy link
Contributor Author

@shreyanavigyan shreyanavigyan commented Apr 21, 2021

I also noticed something that can cause naming conflicts later. In the function win32_ver the minor version is stored in a variable named min which is also the name of a built-in function. Therefore I propose to change the variable name from min to minor to avoid naming conflicts. I also think the maj variable should be changed to major.

@zooba
Copy link
Member

@zooba zooba commented Apr 21, 2021

If you'd like to make more changes, go ahead. Just let us know when it's ready.

@shreyanavigyan
Copy link
Contributor Author

@shreyanavigyan shreyanavigyan commented Apr 21, 2021

Ok

@shreyanavigyan
Copy link
Contributor Author

@shreyanavigyan shreyanavigyan commented Apr 22, 2021

PR is ready for reviewing and if applicable then merging. (No more commits will be made)

@zooba zooba merged commit 2a3f489 into python:master Apr 22, 2021
11 checks passed
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Apr 22, 2021

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

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Apr 22, 2021

Thanks @shreyanavigyan for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒🤖

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Apr 22, 2021

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

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 22, 2021
…s.getwindowsversion() (pythonGH-25500)

The sys module uses the kernel32.dll version number, which can vary from the "actual" Windows version.
Since the best option for getting the version is WMI (which is expensive), we switch back to launching cmd.exe (which is also expensive, but a lot less code on our part).
sys.getwindowsversion() is not updated to avoid launching executables from that module.
(cherry picked from commit 2a3f489)

Co-authored-by: Shreyan Avigyan <shreyan.avigyan@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 22, 2021
…s.getwindowsversion() (pythonGH-25500)

The sys module uses the kernel32.dll version number, which can vary from the "actual" Windows version.
Since the best option for getting the version is WMI (which is expensive), we switch back to launching cmd.exe (which is also expensive, but a lot less code on our part).
sys.getwindowsversion() is not updated to avoid launching executables from that module.
(cherry picked from commit 2a3f489)

Co-authored-by: Shreyan Avigyan <shreyan.avigyan@gmail.com>
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Apr 22, 2021

GH-25524 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this issue Apr 22, 2021
…s.getwindowsversion() (GH-25500)

The sys module uses the kernel32.dll version number, which can vary from the "actual" Windows version.
Since the best option for getting the version is WMI (which is expensive), we switch back to launching cmd.exe (which is also expensive, but a lot less code on our part).
sys.getwindowsversion() is not updated to avoid launching executables from that module.
(cherry picked from commit 2a3f489)

Co-authored-by: Shreyan Avigyan <shreyan.avigyan@gmail.com>
@shreyanavigyan shreyanavigyan deleted the bpo-43284 branch Apr 22, 2021
zooba pushed a commit that referenced this issue Apr 23, 2021
…s.getwindowsversion() (GH-25500)

The sys module uses the kernel32.dll version number, which can vary from the "actual" Windows version.
Since the best option for getting the version is WMI (which is expensive), we switch back to launching cmd.exe (which is also expensive, but a lot less code on our part).
sys.getwindowsversion() is not updated to avoid launching executables from that module.
(cherry picked from commit 2a3f489)

Co-authored-by: Shreyan Avigyan <shreyan.avigyan@gmail.com>
kreathon pushed a commit to kreathon/cpython that referenced this issue May 2, 2021
…s.getwindowsversion() (pythonGH-25500)

The sys module uses the kernel32.dll version number, which can vary from the "actual" Windows version.
Since the best option for getting the version is WMI (which is expensive), we switch back to launching cmd.exe (which is also expensive, but a lot less code on our part).
sys.getwindowsversion() is not updated to avoid launching executables from that module.
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.

None yet

6 participants