-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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-40459: Fix NameError in platform.py #19855
Conversation
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @corona10: please review the changes made to this pull request. |
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.
Misc/NEWS.d/next/Library/2020-05-02-04-29-31.bpo-40459.fSAYVD.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Lib/platform.py
Outdated
with winreg.OpenKeyEx(HKEY_LOCAL_MACHINE, cvkey) as key: | ||
ptype = QueryValueEx(key, 'CurrentType')[0] | ||
with winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, cvkey) as key: | ||
ptype = winreg.QueryValueEx(key, 'CurrentType')[0] | ||
except: |
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.
Maybe this bug was never seend because of "except: pass". It's maybe time to use more precise errors?
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.
Is except OSError:
acceptable? Or are there any situations where this would raise an exception other than an OSError
? And if so, is there a good reason why those are currently passing silently?
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.
win32_edition() doesn't have the typo and it uses "except OSError: pass", so yeah I think that "except OSError:" is reasonable here.
@@ -0,0 +1 @@ | |||
Fix :exc:`NameError` caused from :func:`platform.win32_ver`. |
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.
The NEWS entry doesn't really explain the behavior change for users.
It seems like previously, ptype was always an empty string. ptype is now filled with the value of the "SOFTWARE\Microsoft\Windows NT\CurrentVersion" registry entry.
Can someone test on Windows to see how this string look like? I'm curious :-)
The documentation says:
As a hint: ptype is 'Uniprocessor Free' on single processor NT machines and 'Multiprocessor Free' on multi processor machines. The ‘Free’ refers to the OS version being free of debugging code. It could also state ‘Checked’ which means the OS version uses debugging code, i.e. code that checks arguments, ranges, etc.
https://docs.python.org/dev/library/platform.html#platform.win32_ver
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.
Please explain that this change fix the ptype part of :func:platform.win32_ver
result.
@vstinner On my machine, this was before the change:
and after the change:
|
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.
ptype is empty since this change:
commit d307d05350e26a7a5f8f74db9af632a15215b50f
Author: Steve Dower <steve.dower@microsoft.com>
Date: Mon Apr 22 11:40:12 2019 -0700
Fixes platform.win32_ver on non-Windows platforms (GH-12912)
Hum, it seems like it's a regression introduced in Python 3.7.4.
In this case, it sounds ok to backport the change to Python 3.7 and 3.8.
Lib/platform.py
Outdated
with winreg.OpenKeyEx(HKEY_LOCAL_MACHINE, cvkey) as key: | ||
ptype = QueryValueEx(key, 'CurrentType')[0] | ||
with winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, cvkey) as key: | ||
ptype = winreg.QueryValueEx(key, 'CurrentType')[0] | ||
except: |
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.
win32_edition() doesn't have the typo and it uses "except OSError: pass", so yeah I think that "except OSError:" is reasonable here.
@@ -0,0 +1 @@ | |||
Fix :exc:`NameError` caused from :func:`platform.win32_ver`. |
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.
Please explain that this change fix the ptype part of :func:platform.win32_ver
result.
@corona10: Are you ok to take this change as the opportunity to replace "except: pass" with "except OSError: pass" to detect similar regressions in the future? |
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, now it LGTM.
@corona10: Would you mind to review the updated PR? If you are ok with it, please merge it.
Would it be worth it to add a test case like @unittest.skipUnless(sys.platform.startswith('win'), "windows only test")
def test_win32_ver(self):
release, version, csd, ptype = platform.win32_ver()
# are these all of the possibilities?
ptype_options = ["Multiprocessor Free",
"Multiprocessor Checked",
"Uniprocessor Free",
"Uniprocessor Checked"]
self.assertIn(ptype, ptype_options) in test_platform? |
I expect that such test will likely fail on some specific Windows versions. I don't think that it's worth it. |
I approved the PR, there is no need to modify it anymore. Since there was a disagreement previously on the except, I'm now waiting for @corona10. |
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 again :)
Thanks for the work @sweeneyde and for the review @vstinner
Thanks @sweeneyde for the PR, and @corona10 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8. |
GH-19912 is a backport of this pull request to the 3.8 branch. |
(cherry picked from commit 1e7e451) Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
(cherry picked from commit 1e7e451) Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
GH-19913 is a backport of this pull request to the 3.7 branch. |
Thanks for the fix @sweeneyde! I didn't expect that it would fix a real bug ;-) It's even better! |
https://bugs.python.org/issue40459