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

winVersion.isWin10: accept both int and str for Windows 10 version parameter #11796

Closed
wants to merge 6 commits into from
33 changes: 19 additions & 14 deletions source/winVersion.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2006-2020 NV Access Limited
# Copyright (C) 2006-2020 NV Access Limited, Bill Dengler, Joseph Lee
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

import sys
import os
from typing import Union
import winUser

winVersion=sys.getwindowsversion()
Expand All @@ -28,36 +29,40 @@ def isUwpOcrAvailable():


WIN10_VERSIONS_TO_BUILDS = {
1507: 10240,
1511: 10586,
1607: 14393,
1703: 15063,
1709: 16299,
1803: 17134,
1809: 17763,
1903: 18362,
1909: 18363,
2004: 19041,
2009: 19042,
"1507": 10240,
"1511": 10586,
"1607": 14393,
"1703": 15063,
"1709": 16299,
"1803": 17134,
"1809": 17763,
"1903": 18362,
"1909": 18363,
"2004": 19041,
"20H2": 19042,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the sudden API change from build IDs to xxhx strings. Can we somehow support both? (in other words, 1903 is also 19H1)

}


def isWin10(version: int = 1507, atLeast: bool = True):
def isWin10(version: Union[int, str] = 1507, atLeast: bool = True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could become a mistake from and API sense. This will result in a very hard to untangle confusion between version and build.

It's also not clear on first glance (without reading the docs / implementation) that this function tells you if the OS is a particular version or greater or if it tells you that the versions string is a valid one for Windows 10.

To fix this it might be helpful to keep but deprecate the version keyword, and introduce matchesVersionOrLater: str and a matchesBuildOrLater: int keywords. Alternatively have two separate public functions (which could share a private implementation if it is appropriate).

Another alternative, would be a new getWinVer() function that returned a class type that handled comparison operators and could also be constructed by a build string / int. Allowing you to write code like"

if winVer('20H2') < getWinVer() < winVer('21H2'):
    print("in expected range or releases")

"""
Returns True if NVDA is running on the supplied release version of Windows 10. If no argument is supplied, returns True for all public Windows 10 releases.
@param version: a release version of Windows 10 (such as 1903).
@param atLeast: return True if NVDA is running on at least this Windows 10 build (i.e. this version or higher).
"""
if winVersion.major != 10:
return False
# #11795: October 2020 Update is actually 20H2, not 2009.
if isinstance(version, int):
version = str(version)
assert isinstance(version, str)
try:
if atLeast:
return winVersion.build >= WIN10_VERSIONS_TO_BUILDS[version]
else:
return winVersion.build == WIN10_VERSIONS_TO_BUILDS[version]
except KeyError:
from logHandler import log
log.error("Unknown Windows 10 version {}".format(version))
log.error(f"Unknown Windows 10 version {version}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this

return False


Expand Down