Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type errors for pointer_input.py, wheel_input.py and firefox/options.py #14476

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion py/selenium/webdriver/chromium/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import typing
from io import IOBase

from selenium.types import SubprocessStdAlias
from selenium.webdriver.common import service
Expand Down Expand Up @@ -44,7 +45,9 @@ def __init__(

if isinstance(log_output, str):
self.service_args.append(f"--log-path={log_output}")
self.log_output = None
self.log_output: typing.Optional[IOBase] = None
elif isinstance(log_output, IOBase):
self.log_output = log_output
else:
self.log_output = log_output

Expand Down
3 changes: 2 additions & 1 deletion py/selenium/webdriver/common/actions/pointer_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import typing
from typing import Union

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

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

def encode(self):
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/common/actions/wheel_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ def create_scroll(self, x: int, y: int, delta_x: int, delta_y: int, duration: in
}
)

def create_pause(self, pause_duration: float) -> None:
def create_pause(self, pause_duration: Union[int, float] = 0) -> None:
self.add_action({"type": "pause", "duration": int(pause_duration * 1000)})
15 changes: 10 additions & 5 deletions py/selenium/webdriver/firefox/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any
from typing import Dict
from typing import Optional
from typing import Union

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

@property
Expand All @@ -60,7 +63,7 @@ def binary(self, new_binary: Union[str, FirefoxBinary]) -> None:
``FirefoxBinary`` instance."""
if isinstance(new_binary, FirefoxBinary):
new_binary = new_binary._start_cmd
self.binary_location = new_binary
self.binary_location = str(new_binary)

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

@property
def profile(self) -> FirefoxProfile:
def profile(self) -> Optional[FirefoxProfile]:
""":Returns: The Firefox profile to use."""
return self._profile

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

def enable_mobile(self, android_package: str = "org.mozilla.firefox", android_activity=None, device_serial=None):
def enable_mobile(
self, android_package: Optional[str] = "org.mozilla.firefox", android_activity=None, device_serial=None
):
super().enable_mobile(android_package, android_activity, device_serial)

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

if self._binary_location:
opts["binary"] = self._binary_location
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/wpewebkit/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
log_output=log_output,
env=env,
**kwargs,
) # type: ignore
)

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