8000 fix hkey cleanup · pythonnet/pythonnet@af77fc4 · GitHub
[go: up one dir, main page]

Skip to content

Commit af77fc4

Browse files
committed
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 b147b16 commit af77fc4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
5959
paths_to_check = []
6060
hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
6161
try:
62-
hkey = None
6362
for key_to_check in keys_to_check:
6463
sdk_name, key, value_name = key_to_check[:3]
6564
suffix = key_to_check[3] if len(key_to_check) > 3 else None
65+
hkey = None
6666
try:
6767
hkey = _winreg.OpenKey(hreg, key)
6868
val, type_ = _winreg.QueryValueEx(hkey, value_name)
@@ -74,7 +74,8 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
7474
except WindowsError:
7575
pass
7676
finally:
77-
hkey.Close()
77+
if hkey:
78+
hkey.Close()
7879
finally:
7980
hreg.Close()
8081

0 commit comments

Comments
 (0)
0