Skip to content

Commit 334b760

Browse files
[py] Fix mypy errors (#16283)
1 parent 3491e41 commit 334b760

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

py/selenium/webdriver/common/actions/interaction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
# under the License.
1717
from typing import Union
1818

19+
from .input_device import InputDevice
20+
1921
KEY = "key"
2022
POINTER = "pointer"
2123
NONE = "none"
2224
WHEEL = "wheel"
23-
SOURCE_TYPES = {KEY, POINTER, NONE}
25+
SOURCE_TYPES = {KEY, POINTER, WHEEL, NONE}
2426

2527
POINTER_MOUSE = "mouse"
2628
POINTER_TOUCH = "touch"
@@ -32,7 +34,7 @@
3234
class Interaction:
3335
PAUSE = "pause"
3436

35-
def __init__(self, source: str) -> None:
37+
def __init__(self, source: InputDevice) -> None:
3638
self.source = source
3739

3840

py/selenium/webdriver/common/actions/key_actions.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from __future__ import annotations
1919

2020
from ..utils import keys_to_typing
21-
from .interaction import KEY, POINTER, WHEEL, Interaction
21+
from .interaction import KEY, Interaction
2222
from .key_input import KeyInput
2323
from .pointer_input import PointerInput
2424
from .wheel_input import WheelInput
@@ -29,18 +29,7 @@ def __init__(self, source: KeyInput | PointerInput | WheelInput | None = None) -
2929
if source is None:
3030
source = KeyInput(KEY)
3131
self.input_source = source
32-
33-
# Determine the correct source type string based on the input object
34-
if isinstance(source, KeyInput):
35-
source_type = KEY
36-
elif isinstance(source, PointerInput):
37-
source_type = POINTER
38-
elif isinstance(source, WheelInput):
39-
source_type = WHEEL
40-
else:
41-
source_type = KEY
42-
43-
super().__init__(source_type)
32+
super().__init__(source)
4433

4534
def key_down(self, letter: str) -> KeyActions:
4635
return self._key_action("create_key_down", letter)
@@ -60,6 +49,6 @@ def send_keys(self, text: str | list) -> KeyActions:
6049
return self
6150

6251
def _key_action(self, action: str, letter) -> KeyActions:
63-
meth = getattr(self.input_source, action)
52+
meth = getattr(self.source, action)
6453
meth(letter)
6554
return self

py/selenium/webdriver/common/actions/wheel_actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
from typing import Optional
1919

20-
from .interaction import Interaction
20+
from .interaction import WHEEL, Interaction
2121
from .wheel_input import WheelInput
2222

2323

2424
class WheelActions(Interaction):
2525
def __init__(self, source: Optional[WheelInput] = None):
2626
if source is None:
27-
source = WheelInput("wheel")
27+
source = WheelInput(WHEEL)
2828
super().__init__(source)
2929

3030
def pause(self, duration: float = 0):

0 commit comments

Comments
 (0)