Skip to content

Commit ed794f7

Browse files
pallavigitworknavin772cgoldberg
authored
[py] Fix mypy type annotation issues in action_builder (#16207)
Co-authored-by: Navin Chandra <[email protected]> Co-authored-by: Corey Goldberg <[email protected]>
1 parent c585e6a commit ed794f7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

py/selenium/webdriver/common/actions/action_builder.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from typing import Optional, Union
18+
19+
from typing import Any, Optional, Union
1920

2021
from selenium.webdriver.remote.command import Command
2122

@@ -40,7 +41,7 @@ def __init__(
4041
mouse = mouse or PointerInput(interaction.POINTER_MOUSE, "mouse")
4142
keyboard = keyboard or KeyInput(interaction.KEY)
4243
wheel = wheel or WheelInput(interaction.WHEEL)
43-
self.devices = [mouse, keyboard, wheel]
44+
self.devices: list[Union[PointerInput, KeyInput, WheelInput]] = [mouse, keyboard, wheel]
4445
self._key_action = KeyActions(keyboard)
4546
self._pointer_action = PointerActions(mouse, duration=duration)
4647
self._wheel_action = WheelActions(wheel)
@@ -62,11 +63,11 @@ def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInp
6263

6364
@property
6465
def pointer_inputs(self) -> list[PointerInput]:
65-
return [device for device in self.devices if device.type == interaction.POINTER]
66+
return [device for device in self.devices if isinstance(device, PointerInput)]
6667

6768
@property
6869
def key_inputs(self) -> list[KeyInput]:
69-
return [device for device in self.devices if device.type == interaction.KEY]
70+
return [device for device in self.devices if isinstance(device, KeyInput)]
7071

7172
@property
7273
def key_action(self) -> KeyActions:
@@ -159,7 +160,7 @@ def perform(self) -> None:
159160
>>> el = driver.find_element(id: "some_id")
160161
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys").perform()
161162
"""
162-
enc = {"actions": []}
163+
enc: dict[str, list[Any]] = {"actions": []}
163164
for device in self.devices:
164165
encoded = device.encode()
165166
if encoded["actions"]:

0 commit comments

Comments
 (0)