Skip to content

An AI Agent that interacts with Windows OS at GUI level.

Python

Fix ruff violations in uia module to unblock CI lint step

jeomondb00519fb8d8
diff --git a/pyproject.toml b/pyproject.toml
index 712c5bd..e0742aa 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -95,3 +95,6 @@ indent-style = "space"
[tool.ruff.lint]
select = ["E", "W", "F", "I", "UP"]
ignore = ["E501"]
+
+[tool.ruff.lint.per-file-ignores]
+"windows_use/uia/*.py" = ["F403", "F405", "F811", "E402"]
diff --git a/windows_use/uia/controls.py b/windows_use/uia/controls.py
index 8cee6de..1bd1084 100644
--- a/windows_use/uia/controls.py
+++ b/windows_use/uia/controls.py
@@ -312,7 +312,7 @@ class Control:
"""Get the cached control type name."""
try:
return ControlTypeNames.get(self.CachedControlType, "Unknown")
- except:
+ except Exception:
return "Unknown"
@property
diff --git a/windows_use/uia/core.py b/windows_use/uia/core.py
index e5ce1d4..f2d50c9 100644
--- a/windows_use/uia/core.py
+++ b/windows_use/uia/core.py
@@ -1033,7 +1033,7 @@ def DwmIsCompositionEnabled() -> bool:
return bool(isEnabled.value)
else:
return False
- except:
+ except Exception:
return False
@@ -1056,7 +1056,7 @@ def DwmGetWindowExtendFrameBounds(handle: int) -> Rect | None:
if hr == S_OK:
return Rect(rect.left, rect.top, rect.right, rect.bottom)
return None
- except:
+ except Exception:
return None
@@ -1418,7 +1418,7 @@ def SendKeys(
if hold:
if upperKey in SpecialKeyNames:
keyValue = SpecialKeyNames[upperKey]
- if type(lastKeyValue) == type(keyValue) and lastKeyValue == keyValue:
+ if type(lastKeyValue) is type(keyValue) and lastKeyValue == keyValue:
insertIndex += 1
printKeys.insert(insertIndex, (key[0], "KeyDown | ExtendedKey"))
printKeys.insert(insertIndex + 1, (key[0], "KeyUp | ExtendedKey"))
@@ -1433,7 +1433,7 @@ def SendKeys(
lastKeyValue = keyValue
elif key[0] in CharacterCodes:
keyValue = CharacterCodes[key[0]]
- if type(lastKeyValue) == type(keyValue) and lastKeyValue == keyValue:
+ if type(lastKeyValue) is type(keyValue) and lastKeyValue == keyValue:
insertIndex += 1
printKeys.insert(insertIndex, (key[0], "KeyDown | ExtendedKey"))
printKeys.insert(insertIndex + 1, (key[0], "KeyUp | ExtendedKey"))
@@ -1502,7 +1502,7 @@ def SendKeys(
keyValue = CharacterCodes[text[i]]
if (
include
- and type(lastKeyValue) == type(keyValue)
+ and type(lastKeyValue) is type(keyValue)
and lastKeyValue == keyValue
):
insertIndex += 1
@@ -1773,7 +1773,7 @@ def GetProcesses(detailedInfo: bool = True) -> list[ProcessInfo]:
ctypes.windll.psapi.GetModuleFileNameExW(
hProcess, hModule, exePath, len(exePath)
)
- except:
+ except Exception:
# strlen =
ctypes.windll.kernel32.GetModuleFileNameExW(
hProcess, hModule, exePath, len(exePath)
diff --git a/windows_use/uia/patterns.py b/windows_use/uia/patterns.py
index a975d26..f14b918 100644
--- a/windows_use/uia/patterns.py
+++ b/windows_use/uia/patterns.py
@@ -95,79 +95,79 @@ def GetPatternIdInterface(patternId: int):
_PatternIdInterfaces[PatternId.AnnotationPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationAnnotationPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.CustomNavigationPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationCustomNavigationPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.DragPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationDragPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.DropTargetPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationDropTargetPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.ObjectModelPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationObjectModelPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.SpreadsheetItemPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationSpreadsheetItemPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.SpreadsheetPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationSpreadsheetPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.StylesPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationStylesPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.SelectionPattern2] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationSelectionPattern2
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.TextChildPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationTextChildPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.TextEditPattern] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationTextEditPattern
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.TextPattern2] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationTextPattern2
)
- except:
+ except Exception:
pass
try:
_PatternIdInterfaces[PatternId.TransformPattern2] = (
_AutomationClient.instance().UIAutomationCore.IUIAutomationTransformPattern2
)
- except:
+ except Exception:
pass
return _PatternIdInterfaces[patternId]
@@ -387,7 +387,7 @@ class ExpandCollapsePattern:
ret = self.pattern.Collapse() == S_OK
time.sleep(waitTime)
return ret
- except:
+ except Exception:
pass
return False
@@ -402,7 +402,7 @@ class ExpandCollapsePattern:
ret = self.pattern.Expand() == S_OK
time.sleep(waitTime)
return ret
- except:
+ except Exception:
pass
return False