Skip to content

Commit 315bfc8

Browse files
committed
lint fixes
1 parent 18d68e2 commit 315bfc8

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

robocorp-code/src/robocorp_code/inspector/java/java_inspector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import List, Optional, TypedDict, cast
22

3-
from JABWrapper.context_tree import ContextNode
4-
from JABWrapper.jab_wrapper import JavaWindow
3+
from JABWrapper.context_tree import ContextNode # type: ignore
4+
from JABWrapper.jab_wrapper import JavaWindow # type: ignore
55
from robocorp_ls_core.robotframework_log import get_logger
66

77
from robocorp_code.inspector.java.robocorp_java._inspector import ColletedTreeTypedDict
@@ -18,7 +18,7 @@
1818
)
1919

2020
LocatorNodeInfoTypedDict = TypedDict(
21-
"LocatorNoneInfoTypedDict",
21+
"LocatorNodeInfoTypedDict",
2222
{
2323
"name": str,
2424
"role": str,
@@ -70,7 +70,7 @@ def to_matches_and_hierarchy(
7070
else [str(match) for match in matches_and_hierarchy["matches"]]
7171
)
7272
hierarchy = [to_locator_info(node) for node in matches_and_hierarchy["tree"]]
73-
return {"matches": matches, "hierarchy": hierarchy}
73+
return {"matched_paths": matches, "hierarchy": hierarchy}
7474

7575

7676
class JavaInspector:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
class NoMatchingLocatorException(Exception):
22
"""Match for locator not found."""
3+
4+
5+
class ContextNotAvailable(Exception):
6+
"""The Java context has not been created yet."""

robocorp-code/src/robocorp_code/inspector/java/robocorp_java/_event_pump.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import ctypes
2+
import platform
23
import queue
34
import threading
45
import time
56

6-
from JABWrapper.jab_wrapper import JavaAccessBridgeWrapper
7+
from JABWrapper.jab_wrapper import JavaAccessBridgeWrapper # type: ignore
78
from robocorp_ls_core.robotframework_log import get_logger
89

9-
PeekMessage = ctypes.windll.user32.PeekMessageW
10-
GetMessage = ctypes.windll.user32.GetMessageW
11-
TranslateMessage = ctypes.windll.user32.TranslateMessage
12-
DispatchMessage = ctypes.windll.user32.DispatchMessageW
13-
1410
log = get_logger(__name__)
1511

1612

@@ -24,11 +20,15 @@ def __init__(
2420
super().__init__()
2521
# Jab wrapper needs to be part of the thread that pumps the window events
2622
self._jab_wrapper: JavaAccessBridgeWrapper = None
27-
self._queue = queue.Queue()
23+
self._queue: queue.Queue = queue.Queue()
2824
self._quit_queue_loop = threading.Event()
2925

3026
def _pump_background(self) -> bool:
3127
try:
28+
PeekMessage = ctypes.windll.user32.PeekMessageW # type: ignore
29+
TranslateMessage = ctypes.windll.user32.TranslateMessage # type: ignore
30+
DispatchMessage = ctypes.windll.user32.DispatchMessageW # type: ignore
31+
3232
message = ctypes.byref(ctypes.wintypes.MSG())
3333
# Nonblocking API to get windows window events from the queue.
3434
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-peekmessagea
@@ -45,6 +45,9 @@ def _pump_background(self) -> bool:
4545
return False
4646

4747
def run(self) -> None:
48+
if platform.system() != "Windows":
49+
return
50+
4851
self._jab_wrapper = JavaAccessBridgeWrapper(ignore_callbacks=True)
4952
self._queue.put(self._jab_wrapper)
5053
while not self._quit_queue_loop.is_set():

robocorp-code/src/robocorp_code/inspector/java/robocorp_java/_inspector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self) -> None:
1717
self._context: Optional[ContextNode] = None
1818

1919
def _start_event_pump(func, *args, **kwargs):
20-
def wrapper(self: "ElementInspector", *args, **kwargs):
20+
def wrapper(self, *args, **kwargs):
2121
from ._event_pump import EventPumpThread
2222

2323
event_pump_thread = EventPumpThread()
@@ -54,12 +54,16 @@ def _collect_from_context(
5454
) -> ColletedTreeTypedDict:
5555
from threading import RLock
5656

57-
from ._errors import NoMatchingLocatorException
57+
from ._errors import ContextNotAvailable, NoMatchingLocatorException
5858
from ._locators import find_elements_from_tree
5959

6060
# The JavaAccessBridgeWrapper object needs to be inserted into the context as the
6161
# object has to be recreated every time we do a new query
6262
# TODO: update the ContextTree to introduce the API for this
63+
if not self._context:
64+
raise ContextNotAvailable(
65+
"Cannot search from context as it hasn't been created yet"
66+
)
6367
self._context._jab_wrapper = jab_wrapper
6468
match = find_elements_from_tree(self._context, locator)
6569
node = match[0] if isinstance(match, List) and len(match) > 0 else match

robocorp-code/src/robocorp_code/inspector/java/robocorp_java/_locators.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import List, Optional, Union
22

3-
from JABWrapper.context_tree import ContextNode, ContextTree, SearchElement
3+
from JABWrapper.context_tree import ( # type: ignore
4+
ContextNode,
5+
ContextTree,
6+
SearchElement,
7+
)
48

59
IntegerLocatorTypes = [
610
"x",
@@ -29,7 +33,7 @@ def _parse_locator(locator: str, strict_default=False):
2933
elif parts[0].lower() == "strict":
3034
strict_mode = bool(parts[1])
3135
continue
32-
elif parts[0] in IntegerLocatorTypes:
36+
elif len(parts) > 1 and parts[0] in IntegerLocatorTypes:
3337
try:
3438
parts[1] = int(parts[1])
3539
except ValueError as err:

0 commit comments

Comments
 (0)