Skip to content

Commit ef1f9ce

Browse files
authored
chore: refactor mapping wrappers (#93)
1 parent 6cb0ce4 commit ef1f9ce

File tree

5 files changed

+169
-657
lines changed

5 files changed

+169
-657
lines changed

playwright/accessibility.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ async def snapshot(
6262
) -> Optional[Dict[str, Any]]:
6363
root = root._channel if root else None
6464
result = await self._channel.send(
65-
"accessibilitySnapshot",
66-
dict(root=root, interestingOnly=interestingOnly),
67-
unpack_first_key=False,
68-
)
69-
return (
70-
_ax_node_from_protocol(result["rootAXNode"])
71-
if result.get("rootAXNode")
72-
else None
65+
"accessibilitySnapshot", dict(root=root, interestingOnly=interestingOnly),
7366
)
67+
return _ax_node_from_protocol(result) if result else None

playwright/connection.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,20 @@ def __init__(self, scope: "ConnectionScope", guid: str) -> None:
3030
self._guid = guid
3131
self._object: Optional[ChannelOwner] = None
3232

33-
async def send(
34-
self, method: str, params: dict = None, unpack_first_key: bool = True
35-
) -> Any:
33+
async def send(self, method: str, params: dict = None) -> Any:
3634
if params is None:
3735
params = dict()
3836
result = await self._scope.send_message_to_server(self._guid, method, params)
3937
# Protocol now has named return values, assume result is one level deeper unless
4038
# there is explicit ambiguity.
41-
if unpack_first_key and isinstance(result, dict) and len(result) <= 1:
42-
if len(result) == 1:
43-
key = next(iter(result))
44-
return result[key]
45-
else:
46-
return None
47-
return result
39+
if not result:
40+
return None
41+
assert isinstance(result, dict)
42+
if len(result) == 0:
43+
return None
44+
assert len(result) == 1
45+
key = next(iter(result))
46+
return result[key]
4847

4948
def send_no_reply(self, method: str, params: dict = None) -> None:
5049
if params is None:

0 commit comments

Comments
 (0)