Skip to content

Commit 76e438f

Browse files
Jeomonclaude
andcommitted
Fix NameError: restore Optional import in uia/patterns.py
ruff's --fix removed Optional from patterns.py imports (F401) after UP007 converted some usages, but Optional["TextRange"] string annotations at lines 1412/1426 still require it at runtime. Restored the import and converted the remaining non-string Optional[X] usages (UP045) to X | None. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent db00519 commit 76e438f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

windows_use/uia/patterns.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os
1616
import sys
1717
import time
18-
from typing import TYPE_CHECKING, Any
18+
from typing import TYPE_CHECKING, Any, Optional
1919

2020
from .core import *
2121
from .core import _AutomationClient
@@ -1634,7 +1634,7 @@ def __init__(self, pattern=None):
16341634
"""Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtexteditpattern"""
16351635
self.pattern = pattern
16361636

1637-
def GetActiveComposition(self) -> Optional[TextRange]:
1637+
def GetActiveComposition(self) -> TextRange | None:
16381638
"""
16391639
Call IUIAutomationTextEditPattern::GetActiveComposition.
16401640
Return `TextRange` or None, the active composition.
@@ -1645,7 +1645,7 @@ def GetActiveComposition(self) -> Optional[TextRange]:
16451645
return TextRange(textRange=textRange)
16461646
return None
16471647

1648-
def GetConversionTarget(self) -> Optional[TextRange]:
1648+
def GetConversionTarget(self) -> TextRange | None:
16491649
"""
16501650
Call IUIAutomationTextEditPattern::GetConversionTarget.
16511651
Return `TextRange` or None, the current conversion target range..
@@ -1713,7 +1713,7 @@ def GetVisibleRanges(self) -> list[TextRange]:
17131713
return textRanges
17141714
return []
17151715

1716-
def RangeFromChild(self, child) -> Optional[TextRange]:
1716+
def RangeFromChild(self, child) -> TextRange | None:
17171717
"""
17181718
Call IUIAutomationTextPattern::RangeFromChild.
17191719
child: `Control` or its subclass.
@@ -1726,7 +1726,7 @@ def RangeFromChild(self, child) -> Optional[TextRange]:
17261726
return TextRange(textRange=textRange)
17271727
return None
17281728

1729-
def RangeFromPoint(self, x: int, y: int) -> Optional[TextRange]:
1729+
def RangeFromPoint(self, x: int, y: int) -> TextRange | None:
17301730
"""
17311731
Call IUIAutomationTextPattern::RangeFromPoint.
17321732
child: `Control` or its subclass.

0 commit comments

Comments
 (0)