prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  winVersion.isWin10: modify it to return early if major is not 10
  Hi,
  
  This feature request should not be done for 2019.3 in order to avoid introducing possible regressions, but perhaps defer it to 2020.1:
  
  ### Is your feature request related to a problem? Please describe.
  In NVDA 2019.2, as part of UIA console support, winVersion module introduced isWin10 function which returns whether a system is running a specific version of Windows 10 or later. At the moment it checks major version in two places:
  
  * If "at least" flag is specified: return False if version is less than 10.
  * If "at least" flag is not specified: return False if major version is not 10.
  
  At least it is understandable. But I would argue that for sake of performance and keeping the subject line and body in sync, I propose the below modification.
  
  ### Describe the solution you'd like
  Instead of checking flags after defining version information map, return early if major version isn't even 10. Not only flag checks can be avoided on Windows 8.1 and earlier, it can make the function body in line with what the function title says.
  
  Thus I propose:
  
  1. First, check winVersion.major and return False if it isn't 10.
  2. Define version to build map.
  3. Same as current function.
  
  ### Describe alternatives you've considered
  Keep the function as is.
  
  ### Additional context
  I'm sure there might be other opportunities to optimize this function, but that's in the future.
  
  Thanks.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `source/winVersion.py`
  Content:
  ```
  1 # A part of NonVisual Desktop Access (NVDA)
  2 # Copyright (C) 2006-2019 NV Access Limited
  3 # This file is covered by the GNU General Public License.
  4 # See the file COPYING for more details.
  5 
  6 import sys
  7 import os
  8 import winUser
  9 
  10 winVersion=sys.getwindowsversion()
  11 winVersionText="{v.major}.{v.minor}.{v.build}".format(v=winVersion)
  12 if winVersion.service_pack_major!=0:
  13 	winVersionText+=" service pack %d"%winVersion.service_pack_major
  14 	if winVersion.service_pack_minor!=0:
  15 		winVersionText+=".%d"%winVersion.service_pack_minor
  16 winVersionText+=" %s" % ("workstation","domain controller","server")[winVersion.product_type-1]
  17 
  18 def isSupportedOS():
  19 	# NVDA can only run on Windows 7 Service pack 1 and above
  20 	return (winVersion.major,winVersion.minor,winVersion.service_pack_major) >= (6,1,1)
  21 
  22 def canRunVc2010Builds():
  23 	return isSupportedOS()
  24 
  25 UWP_OCR_DATA_PATH = os.path.expandvars(r"$windir\OCR")
  26 def isUwpOcrAvailable():
  27 	return os.path.isdir(UWP_OCR_DATA_PATH)
  28 
  29 def isWin10(version=1507, atLeast=True):
  30 	"""
  31 	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.
  32 	@param version: a release version of Windows 10 (such as 1903).
  33 	@param atLeast: return True if NVDA is running on at least this Windows 10 build (i.e. this version or higher).
  34 	"""
  35 	from logHandler import log
  36 	win10VersionsToBuilds={
  37 		1507: 10240,
  38 		1511: 10586,
  39 		1607: 14393,
  40 		1703: 15063,
  41 		1709: 16299,
  42 		1803: 17134,
  43 		1809: 17763,
  44 		1903: 18362,
  45 		1909: 18363,
  46 	}
  47 	if atLeast and winVersion.major < 10:
  48 		return False
  49 	elif not atLeast and winVersion.major != 10:
  50 		return False
  51 	try:
  52 		if atLeast:
  53 			return winVersion.build >= win10VersionsToBuilds[version]
  54 		else:
  55 			return winVersion.build == win10VersionsToBuilds[version]
  56 	except KeyError:
  57 		log.error("Unknown Windows 10 version {}".format(version))
  58 		return False
  59 
  60 
  61 def isFullScreenMagnificationAvailable():
  62 	return (winVersion.major, winVersion.minor) >= (6, 2)
  63
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/source/winVersion.py b/source/winVersion.py
  --- a/source/winVersion.py
  +++ b/source/winVersion.py
  @@ -26,34 +26,35 @@
   def isUwpOcrAvailable():
   	return os.path.isdir(UWP_OCR_DATA_PATH)
   
  -def isWin10(version=1507, atLeast=True):
  +
  +WIN10_VERSIONS_TO_BUILDS = {
  +	1507: 10240,
  +	1511: 10586,
  +	1607: 14393,
  +	1703: 15063,
  +	1709: 16299,
  +	1803: 17134,
  +	1809: 17763,
  +	1903: 18362,
  +	1909: 18363,
  +}
  +
  +
  +def isWin10(version: int = 1507, atLeast: bool = True):
   	"""
   	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).
   	"""
  -	from logHandler import log
  -	win10VersionsToBuilds={
  -		1507: 10240,
  -		1511: 10586,
  -		1607: 14393,
  -		1703: 15063,
  -		1709: 16299,
  -		1803: 17134,
  -		1809: 17763,
  -		1903: 18362,
  -		1909: 18363,
  -	}
  -	if atLeast and winVersion.major < 10:
  -		return False
  -	elif not atLeast and winVersion.major != 10:
  +	if winVersion.major != 10:
   		return False
   	try:
   		if atLeast:
  -			return winVersion.build >= win10VersionsToBuilds[version]
  +			return winVersion.build >= WIN10_VERSIONS_TO_BUILDS[version]
   		else:
  -			return winVersion.build == win10VersionsToBuilds[version]
  +			return winVersion.build == WIN10_VERSIONS_TO_BUILDS[version]
   	except KeyError:
  +		from logHandler import log
   		log.error("Unknown Windows 10 version {}".format(version))
   		return False
  
verification_info: {"golden_diff": "diff --git a/source/winVersion.py b/source/winVersion.py\n--- a/source/winVersion.py\n+++ b/source/winVersion.py\n@@ -26,34 +26,35 @@\n def isUwpOcrAvailable():\r\n \treturn os.path.isdir(UWP_OCR_DATA_PATH)\r\n \r\n-def isWin10(version=1507, atLeast=True):\r\n+\r\n+WIN10_VERSIONS_TO_BUILDS = {\r\n+\t1507: 10240,\r\n+\t1511: 10586,\r\n+\t1607: 14393,\r\n+\t1703: 15063,\r\n+\t1709: 16299,\r\n+\t1803: 17134,\r\n+\t1809: 17763,\r\n+\t1903: 18362,\r\n+\t1909: 18363,\r\n+}\r\n+\r\n+\r\n+def isWin10(version: int = 1507, atLeast: bool = True):\r\n \t\"\"\"\r\n \tReturns 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.\r\n \t@param version: a release version of Windows 10 (such as 1903).\r\n \t@param atLeast: return True if NVDA is running on at least this Windows 10 build (i.e. this version or higher).\r\n \t\"\"\"\r\n-\tfrom logHandler import log\r\n-\twin10VersionsToBuilds={\r\n-\t\t1507: 10240,\r\n-\t\t1511: 10586,\r\n-\t\t1607: 14393,\r\n-\t\t1703: 15063,\r\n-\t\t1709: 16299,\r\n-\t\t1803: 17134,\r\n-\t\t1809: 17763,\r\n-\t\t1903: 18362,\r\n-\t\t1909: 18363,\r\n-\t}\r\n-\tif atLeast and winVersion.major < 10:\r\n-\t\treturn False\r\n-\telif not atLeast and winVersion.major != 10:\r\n+\tif winVersion.major != 10:\r\n \t\treturn False\r\n \ttry:\r\n \t\tif atLeast:\r\n-\t\t\treturn winVersion.build >= win10VersionsToBuilds[version]\r\n+\t\t\treturn winVersion.build >= WIN10_VERSIONS_TO_BUILDS[version]\r\n \t\telse:\r\n-\t\t\treturn winVersion.build == win10VersionsToBuilds[version]\r\n+\t\t\treturn winVersion.build == WIN10_VERSIONS_TO_BUILDS[version]\r\n \texcept KeyError:\r\n+\t\tfrom logHandler import log\r\n \t\tlog.error(\"Unknown Windows 10 version {}\".format(version))\r\n \t\treturn False\n", "issue": "winVersion.isWin10: modify it to return early if major is not 10\nHi,\r\n\r\nThis feature request should not be done for 2019.3 in order to avoid introducing possible regressions, but perhaps defer it to 2020.1:\r\n\r\n### Is your feature request related to a problem? Please describe.\r\nIn NVDA 2019.2, as part of UIA console support, winVersion module introduced isWin10 function which returns whether a system is running a specific version of Windows 10 or later. At the moment it checks major version in two places:\r\n\r\n* If \"at least\" flag is specified: return False if version is less than 10.\r\n* If \"at least\" flag is not specified: return False if major version is not 10.\r\n\r\nAt least it is understandable. But I would argue that for sake of performance and keeping the subject line and body in sync, I propose the below modification.\r\n\r\n### Describe the solution you'd like\r\nInstead of checking flags after defining version information map, return early if major version isn't even 10. Not only flag checks can be avoided on Windows 8.1 and earlier, it can make the function body in line with what the function title says.\r\n\r\nThus I propose:\r\n\r\n1. First, check winVersion.major and return False if it isn't 10.\r\n2. Define version to build map.\r\n3. Same as current function.\r\n\r\n### Describe alternatives you've considered\r\nKeep the function as is.\r\n\r\n### Additional context\r\nI'm sure there might be other opportunities to optimize this function, but that's in the future.\r\n\r\nThanks.\n", "before_files": [{"content": "# A part of NonVisual Desktop Access (NVDA)\r\n# Copyright (C) 2006-2019 NV Access Limited\r\n# This file is covered by the GNU General Public License.\r\n# See the file COPYING for more details.\r\n\r\nimport sys\r\nimport os\r\nimport winUser\r\n\r\nwinVersion=sys.getwindowsversion()\r\nwinVersionText=\"{v.major}.{v.minor}.{v.build}\".format(v=winVersion)\r\nif winVersion.service_pack_major!=0:\r\n\twinVersionText+=\" service pack %d\"%winVersion.service_pack_major\r\n\tif winVersion.service_pack_minor!=0:\r\n\t\twinVersionText+=\".%d\"%winVersion.service_pack_minor\r\nwinVersionText+=\" %s\" % (\"workstation\",\"domain controller\",\"server\")[winVersion.product_type-1]\r\n\r\ndef isSupportedOS():\r\n\t# NVDA can only run on Windows 7 Service pack 1 and above\r\n\treturn (winVersion.major,winVersion.minor,winVersion.service_pack_major) >= (6,1,1)\r\n\r\ndef canRunVc2010Builds():\r\n\treturn isSupportedOS()\r\n\r\nUWP_OCR_DATA_PATH = os.path.expandvars(r\"$windir\\OCR\")\r\ndef isUwpOcrAvailable():\r\n\treturn os.path.isdir(UWP_OCR_DATA_PATH)\r\n\r\ndef isWin10(version=1507, atLeast=True):\r\n\t\"\"\"\r\n\tReturns 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.\r\n\t@param version: a release version of Windows 10 (such as 1903).\r\n\t@param atLeast: return True if NVDA is running on at least this Windows 10 build (i.e. this version or higher).\r\n\t\"\"\"\r\n\tfrom logHandler import log\r\n\twin10VersionsToBuilds={\r\n\t\t1507: 10240,\r\n\t\t1511: 10586,\r\n\t\t1607: 14393,\r\n\t\t1703: 15063,\r\n\t\t1709: 16299,\r\n\t\t1803: 17134,\r\n\t\t1809: 17763,\r\n\t\t1903: 18362,\r\n\t\t1909: 18363,\r\n\t}\r\n\tif atLeast and winVersion.major < 10:\r\n\t\treturn False\r\n\telif not atLeast and winVersion.major != 10:\r\n\t\treturn False\r\n\ttry:\r\n\t\tif atLeast:\r\n\t\t\treturn winVersion.build >= win10VersionsToBuilds[version]\r\n\t\telse:\r\n\t\t\treturn winVersion.build == win10VersionsToBuilds[version]\r\n\texcept KeyError:\r\n\t\tlog.error(\"Unknown Windows 10 version {}\".format(version))\r\n\t\treturn False\r\n\r\n\r\ndef isFullScreenMagnificationAvailable():\r\n\treturn (winVersion.major, winVersion.minor) >= (6, 2)\r\n", "path": "source/winVersion.py"}], "after_files": [{"content": "# A part of NonVisual Desktop Access (NVDA)\r\n# Copyright (C) 2006-2019 NV Access Limited\r\n# This file is covered by the GNU General Public License.\r\n# See the file COPYING for more details.\r\n\r\nimport sys\r\nimport os\r\nimport winUser\r\n\r\nwinVersion=sys.getwindowsversion()\r\nwinVersionText=\"{v.major}.{v.minor}.{v.build}\".format(v=winVersion)\r\nif winVersion.service_pack_major!=0:\r\n\twinVersionText+=\" service pack %d\"%winVersion.service_pack_major\r\n\tif winVersion.service_pack_minor!=0:\r\n\t\twinVersionText+=\".%d\"%winVersion.service_pack_minor\r\nwinVersionText+=\" %s\" % (\"workstation\",\"domain controller\",\"server\")[winVersion.product_type-1]\r\n\r\ndef isSupportedOS():\r\n\t# NVDA can only run on Windows 7 Service pack 1 and above\r\n\treturn (winVersion.major,winVersion.minor,winVersion.service_pack_major) >= (6,1,1)\r\n\r\ndef canRunVc2010Builds():\r\n\treturn isSupportedOS()\r\n\r\nUWP_OCR_DATA_PATH = os.path.expandvars(r\"$windir\\OCR\")\r\ndef isUwpOcrAvailable():\r\n\treturn os.path.isdir(UWP_OCR_DATA_PATH)\r\n\r\n\r\nWIN10_VERSIONS_TO_BUILDS = {\r\n\t1507: 10240,\r\n\t1511: 10586,\r\n\t1607: 14393,\r\n\t1703: 15063,\r\n\t1709: 16299,\r\n\t1803: 17134,\r\n\t1809: 17763,\r\n\t1903: 18362,\r\n\t1909: 18363,\r\n}\r\n\r\n\r\ndef isWin10(version: int = 1507, atLeast: bool = True):\r\n\t\"\"\"\r\n\tReturns 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.\r\n\t@param version: a release version of Windows 10 (such as 1903).\r\n\t@param atLeast: return True if NVDA is running on at least this Windows 10 build (i.e. this version or higher).\r\n\t\"\"\"\r\n\tif winVersion.major != 10:\r\n\t\treturn False\r\n\ttry:\r\n\t\tif atLeast:\r\n\t\t\treturn winVersion.build >= WIN10_VERSIONS_TO_BUILDS[version]\r\n\t\telse:\r\n\t\t\treturn winVersion.build == WIN10_VERSIONS_TO_BUILDS[version]\r\n\texcept KeyError:\r\n\t\tfrom logHandler import log\r\n\t\tlog.error(\"Unknown Windows 10 version {}\".format(version))\r\n\t\treturn False\r\n\r\n\r\ndef isFullScreenMagnificationAvailable():\r\n\treturn (winVersion.major, winVersion.minor) >= (6, 2)\r\n", "path": "source/winVersion.py"}]}