Skip to content

Commit 826f8ef

Browse files
committed
resolve mypy errors
1 parent 7e8e7f5 commit 826f8ef

File tree

1 file changed

+24
-26
lines changed
  • py/selenium/webdriver/common/bidi

1 file changed

+24
-26
lines changed

py/selenium/webdriver/common/bidi/input.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# under the License.
1717

1818
import math
19-
from dataclasses import dataclass
20-
from typing import List, Optional, Union
19+
from dataclasses import dataclass, field
20+
from typing import Any, Dict, List, Optional, Union
2121

2222
from selenium.webdriver.common.bidi.common import command_builder
2323
from selenium.webdriver.common.bidi.session import Session
@@ -101,7 +101,7 @@ def __post_init__(self):
101101

102102
def to_dict(self) -> dict:
103103
"""Convert the PointerCommonProperties to a dictionary."""
104-
result = {}
104+
result: Dict[str, Any] = {}
105105
if self.width != 1:
106106
result["width"] = self.width
107107
if self.height != 1:
@@ -132,7 +132,7 @@ def type(self) -> str:
132132

133133
def to_dict(self) -> dict:
134134
"""Convert the PauseAction to a dictionary."""
135-
result = {"type": self.type}
135+
result: Dict[str, Any] = {"type": self.type}
136136
if self.duration is not None:
137137
result["duration"] = self.duration
138138
return result
@@ -181,7 +181,7 @@ def type(self) -> str:
181181

182182
def to_dict(self) -> dict:
183183
"""Convert the PointerDownAction to a dictionary."""
184-
result = {"type": self.type, "button": self.button}
184+
result: Dict[str, Any] = {"type": self.type, "button": self.button}
185185
if self.properties:
186186
result.update(self.properties.to_dict())
187187
return result
@@ -218,7 +218,7 @@ def type(self) -> str:
218218

219219
def to_dict(self) -> dict:
220220
"""Convert the PointerMoveAction to a dictionary."""
221-
result = {"type": self.type, "x": self.x, "y": self.y}
221+
result: Dict[str, Any] = {"type": self.type, "x": self.x, "y": self.y}
222222
if self.duration is not None:
223223
result["duration"] = self.duration
224224
if self.origin is not None:
@@ -248,7 +248,13 @@ def type(self) -> str:
248248

249249
def to_dict(self) -> dict:
250250
"""Convert the WheelScrollAction to a dictionary."""
251-
result = {"type": self.type, "x": self.x, "y": self.y, "deltaX": self.delta_x, "deltaY": self.delta_y}
251+
result: Dict[str, Any] = {
252+
"type": self.type,
253+
"x": self.x,
254+
"y": self.y,
255+
"deltaX": self.delta_x,
256+
"deltaY": self.delta_y,
257+
}
252258
if self.duration is not None:
253259
result["duration"] = self.duration
254260
if self.origin is not None:
@@ -265,11 +271,7 @@ class NoneSourceActions:
265271
"""Represents a sequence of none actions."""
266272

267273
id: str = ""
268-
actions: List[PauseAction] = None
269-
270-
def __post_init__(self):
271-
if self.actions is None:
272-
self.actions = []
274+
actions: List[PauseAction] = field(default_factory=list)
273275

274276
@property
275277
def type(self) -> str:
@@ -285,11 +287,7 @@ class KeySourceActions:
285287
"""Represents a sequence of key actions."""
286288

287289
id: str = ""
288-
actions: List[Union[PauseAction, KeyDownAction, KeyUpAction]] = None
289-
290-
def __post_init__(self):
291-
if self.actions is None:
292-
self.actions = []
290+
actions: List[Union[PauseAction, KeyDownAction, KeyUpAction]] = field(default_factory=list)
293291

294292
@property
295293
def type(self) -> str:
@@ -306,11 +304,11 @@ class PointerSourceActions:
306304

307305
id: str = ""
308306
parameters: Optional[PointerParameters] = None
309-
actions: List[Union[PauseAction, PointerDownAction, PointerUpAction, PointerMoveAction]] = None
307+
actions: List[Union[PauseAction, PointerDownAction, PointerUpAction, PointerMoveAction]] = field(
308+
default_factory=list
309+
)
310310

311311
def __post_init__(self):
312-
if self.actions is None:
313-
self.actions = []
314312
if self.parameters is None:
315313
self.parameters = PointerParameters()
316314

@@ -320,7 +318,11 @@ def type(self) -> str:
320318

321319
def to_dict(self) -> dict:
322320
"""Convert the PointerSourceActions to a dictionary."""
323-
result = {"type": self.type, "id": self.id, "actions": [action.to_dict() for action in self.actions]}
321+
result: Dict[str, Any] = {
322+
"type": self.type,
323+
"id": self.id,
324+
"actions": [action.to_dict() for action in self.actions],
325+
}
324326
if self.parameters:
325327
result["parameters"] = self.parameters.to_dict()
326328
return result
@@ -331,11 +333,7 @@ class WheelSourceActions:
331333
"""Represents a sequence of wheel actions."""
332334

333335
id: str = ""
334-
actions: List[Union[PauseAction, WheelScrollAction]] = None
335-
336-
def __post_init__(self):
337-
if self.actions is None:
338-
self.actions = []
336+
actions: List[Union[PauseAction, WheelScrollAction]] = field(default_factory=list)
339337

340338
@property
341339
def type(self) -> str:

0 commit comments

Comments
 (0)