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-40459: Fix NameError in platform.py #19855

Merged
merged 8 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ def win32_ver(release='', version='', csd='', ptype=''):
else:
try:
cvkey = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion'
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:
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

pass

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :exc:`NameError` caused from :func:`platform.win32_ver`.
Copy link
Member

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

Copy link
Member

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.