Skip to content

Commit fb2013f

Browse files
typing
1 parent 3864da8 commit fb2013f

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

tools/webdriver/webdriver/bidi/protocol.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class BidiValue(ABC):
1010
protocol_value: Dict[str, Any]
1111
type: str
1212

13-
def __init__(self, protocol_value):
13+
def __init__(self, protocol_value: Dict[str, Any]):
1414
assert isinstance(protocol_value, dict)
1515
assert isinstance(protocol_value["type"], str)
1616
self.type = protocol_value["type"]
1717
self.protocol_value = protocol_value
1818

19-
def to_classic_protocol_value(self) -> Dict:
19+
def to_classic_protocol_value(self) -> Dict[str, Any]:
2020
"""Convert the BiDi value to the classic protocol value. Required for compatibility of the values sent over BiDi
2121
transport with the classic actions."""
2222
raise NotImplementedError("No conversion to the classic protocol value is implemented.")
@@ -30,7 +30,7 @@ def __init__(self, protocol_value: Dict[str, Any]):
3030
assert self.type == "node"
3131
self.shared_id = self.protocol_value["sharedId"]
3232

33-
def to_classic_protocol_value(self) -> Dict:
33+
def to_classic_protocol_value(self) -> Dict[str, Any]:
3434
return {WebElement.identifier: self.shared_id}
3535

3636

@@ -43,7 +43,7 @@ def __init__(self, protocol_value: Dict[str, Any]):
4343
self.browsing_context = self.protocol_value["value"]["context"]
4444

4545

46-
def bidi_deserialize(bidi_value: Union[str, int, Dict]):
46+
def bidi_deserialize(bidi_value: Union[str, int, Dict[str, Any]]) -> Any:
4747
"""
4848
Deserialize the BiDi primitive values, lists and objects to the Python value, keeping non-common data types
4949
in BiDi format.
@@ -82,15 +82,15 @@ def bidi_deserialize(bidi_value: Union[str, int, Dict]):
8282
return int(bidi_value["value"])
8383
# script.RemoteValue https://w3c.github.io/webdriver-bidi/#type-script-RemoteValue
8484
if bidi_value["type"] == "array":
85-
result = []
85+
list_result = []
8686
for item in bidi_value["value"]:
87-
result.append(bidi_deserialize(item))
88-
return result
87+
list_result.append(bidi_deserialize(item))
88+
return list_result
8989
if bidi_value["type"] == "object":
90-
result = {}
90+
dict_result = {}
9191
for item in bidi_value["value"]:
92-
result[bidi_deserialize(item[0])] = bidi_deserialize(item[1])
93-
return result
92+
dict_result[bidi_deserialize(item[0])] = bidi_deserialize(item[1])
93+
return dict_result
9494
if bidi_value["type"] == "node":
9595
return BidiNode(bidi_value)
9696
if bidi_value["type"] == "window":

tools/wptrunner/wptrunner/executors/asyncactions.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
from typing import List, Optional, TypedDict, Union
1+
from typing import Any, List, Mapping, Optional, TypedDict, Union
22
from webdriver.bidi.protocol import BidiWindow
3+
from .protocol import BidiEventsProtocolPart
4+
from mozlog.structuredlog import StructuredLogger
35

46

57
class BrowsingContextArgument(str):
68
"""Represent a browsing context argument passed from testdriver. It can be either a browsing context id, or a BiDi
79
serialized window. In the latter case, the value is extracted from the serialized object."""
810

9-
def __new__(cls, context: Union[str, BidiWindow]):
11+
def __new__(cls, context: Union[str, BidiWindow]) -> BrowsingContextArgument:
1012
if isinstance(context, str):
1113
_context_id = context
1214
elif isinstance(context, BidiWindow):
@@ -29,18 +31,18 @@ class Payload(TypedDict):
2931
events: List[str]
3032
contexts: Optional[List[BrowsingContextArgument]]
3133

32-
def __init__(self, logger, protocol):
34+
def __init__(self, logger: StructuredLogger, protocol: Any):
3335
self.logger = logger
34-
self.protocol = protocol
36+
self.bidi_events_protocol: BidiEventsProtocolPart = protocol.bidi_events
3537

36-
async def __call__(self, payload: Payload):
38+
async def __call__(self, payload: Payload) -> Mapping[str, Any]:
3739
events = payload["events"]
3840
contexts = None
3941
if payload["contexts"] is not None:
4042
contexts = []
4143
for browsing_context_argument in payload["contexts"]:
42-
contexts.append(BrowsingContextArgument(browsing_context_argument))
43-
return await self.protocol.bidi_events.subscribe(events, contexts)
44+
contexts.append(str(BrowsingContextArgument(browsing_context_argument)))
45+
return await self.bidi_events_protocol.subscribe(events, contexts)
4446

4547

4648
async_actions = [BidiSessionSubscribeAction]

tools/wptrunner/wptrunner/executors/protocol.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def close_old_windows(self, url_protocol):
205205
pass
206206

207207
@abstractmethod
208-
def get_test_window(self, window_id, parent) -> str:
208+
def get_test_window(self, window_id: str, parent: str) -> str:
209209
"""Get the window handle dorresponding to the window containing the
210210
currently active test.
211211
@@ -331,7 +331,7 @@ class BidiBrowsingContextProtocolPart(ProtocolPart):
331331
async def handle_user_prompt(self,
332332
context: str,
333333
accept: Optional[bool] = None,
334-
user_text: Optional[str] = None):
334+
user_text: Optional[str] = None) -> None:
335335
"""
336336
Allows closing an open prompt.
337337
:param context: The context of the prompt.
@@ -389,7 +389,7 @@ async def call_function(
389389
function_declaration: str,
390390
target: Target,
391391
arguments: Optional[List[Mapping[str, Any]]] = None
392-
):
392+
) -> Mapping[str, Any]:
393393
"""
394394
Executes the provided script in the given target in asynchronous mode.
395395

0 commit comments

Comments
 (0)