Skip to content

Commit 05bce9b

Browse files
navin772harsha509
andauthored
fix type errors for pointer_input.py, wheel_input.py and firefox/options.py (#14476)
* fix type errors fro `firefox/options.py` * fix more mypy errors --------- Co-authored-by: Sri Harsha <[email protected]>
1 parent 49f2f76 commit 05bce9b

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

py/selenium/webdriver/chromium/service.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
import typing
18+
from io import IOBase
1819

1920
from selenium.types import SubprocessStdAlias
2021
from selenium.webdriver.common import service
@@ -44,7 +45,9 @@ def __init__(
4445

4546
if isinstance(log_output, str):
4647
self.service_args.append(f"--log-path={log_output}")
47-
self.log_output = None
48+
self.log_output: typing.Optional[IOBase] = None
49+
elif isinstance(log_output, IOBase):
50+
self.log_output = log_output
4851
else:
4952
self.log_output = log_output
5053

py/selenium/webdriver/common/actions/pointer_input.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
import typing
18+
from typing import Union
1819

1920
from selenium.common.exceptions import InvalidArgumentException
2021
from selenium.webdriver.remote.webelement import WebElement
@@ -60,7 +61,7 @@ def create_pointer_up(self, button):
6061
def create_pointer_cancel(self):
6162
self.add_action({"type": "pointerCancel"})
6263

63-
def create_pause(self, pause_duration: float) -> None:
64+
def create_pause(self, pause_duration: Union[int, float] = 0) -> None:
6465
self.add_action({"type": "pause", "duration": int(pause_duration * 1000)})
6566

6667
def encode(self):

py/selenium/webdriver/common/actions/wheel_input.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ def create_scroll(self, x: int, y: int, delta_x: int, delta_y: int, duration: in
7373
}
7474
)
7575

76-
def create_pause(self, pause_duration: float) -> None:
76+
def create_pause(self, pause_duration: Union[int, float] = 0) -> None:
7777
self.add_action({"type": "pause", "duration": int(pause_duration * 1000)})

py/selenium/webdriver/firefox/options.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
from typing import Any
18+
from typing import Dict
19+
from typing import Optional
1720
from typing import Union
1821

1922
from typing_extensions import deprecated
@@ -44,7 +47,7 @@ def __init__(self) -> None:
4447
# Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference will enable it.
4548
# https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/.
4649
self._preferences["remote.active-protocols"] = 3
47-
self._profile = None
50+
self._profile: Optional[FirefoxProfile] = None
4851
self.log = Log()
4952

5053
@property
@@ -60,7 +63,7 @@ def binary(self, new_binary: Union[str, FirefoxBinary]) -> None:
6063
``FirefoxBinary`` instance."""
6164
if isinstance(new_binary, FirefoxBinary):
6265
new_binary = new_binary._start_cmd
63-
self.binary_location = new_binary
66+
self.binary_location = str(new_binary)
6467

6568
@property
6669
def binary_location(self) -> str:
@@ -84,7 +87,7 @@ def set_preference(self, name: str, value: Union[str, int, bool]):
8487
self._preferences[name] = value
8588

8689
@property
87-
def profile(self) -> FirefoxProfile:
90+
def profile(self) -> Optional[FirefoxProfile]:
8891
""":Returns: The Firefox profile to use."""
8992
return self._profile
9093

@@ -96,7 +99,9 @@ def profile(self, new_profile: Union[str, FirefoxProfile]) -> None:
9699
new_profile = FirefoxProfile(new_profile)
97100
self._profile = new_profile
98101

99-
def enable_mobile(self, android_package: str = "org.mozilla.firefox", android_activity=None, device_serial=None):
102+
def enable_mobile(
103+
self, android_package: Optional[str] = "org.mozilla.firefox", android_activity=None, device_serial=None
104+
):
100105
super().enable_mobile(android_package, android_activity, device_serial)
101106

102107
def to_capabilities(self) -> dict:
@@ -106,7 +111,7 @@ def to_capabilities(self) -> dict:
106111
# it will defer to geckodriver to find the system Firefox
107112
# and generate a fresh profile.
108113
caps = self._caps
109-
opts = {}
114+
opts: Dict[str, Any] = {}
110115

111116
if self._binary_location:
112117
opts["binary"] = self._binary_location

py/selenium/webdriver/wpewebkit/service.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(
4949
log_output=log_output,
5050
env=env,
5151
**kwargs,
52-
) # type: ignore
52+
)
5353

5454
def command_line_args(self) -> typing.List[str]:
5555
return ["-p", f"{self.port}"] + self.service_args

0 commit comments

Comments
 (0)