Skip to content

Commit c9a784b

Browse files
rico-chettonyroberts
authored andcommitted
fix hkey cleanup
fix for AttributeError: 'NoneType' object has no attribute 'Close', full Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\foo\AppData\Local\Temp\pip-clrr6blj-build\setup.py", line 99, in <module> _xbuild = "\"%s\"" % _find_msbuild_tool("msbuild.exe") File "C:\Users\foo\AppData\Local\Temp\pip-clrr6blj-build\setup.py", line 77, in _find_msbuild_tool hkey.Close() AttributeError: 'NoneType' object has no attribute 'Close'
1 parent 990170e commit c9a784b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
6464
paths_to_check = []
6565
hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
6666
try:
67-
hkey = None
6867
for key_to_check in keys_to_check:
6968
sdk_name, key, value_name = key_to_check[:3]
7069
suffix = key_to_check[3] if len(key_to_check) > 3 else None
70+
hkey = None
7171
try:
7272
hkey = _winreg.OpenKey(hreg, key)
7373
val, type_ = _winreg.QueryValueEx(hkey, value_name)
@@ -79,7 +79,8 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
7979
except WindowsError:
8080
pass
8181
finally:
82-
hkey.Close()
82+
if hkey:
83+
hkey.Close()
8384
finally:
8485
hreg.Close()
8586

0 commit comments

Comments
 (0)