From 16c3e248206034d8603ff22f73ce13dc984f38b3 Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Tue, 21 Oct 2025 16:21:58 +0530 Subject: [PATCH 1/3] [py]:Fix mypy type errors in webdriver --- .../webdriver/common/virtual_authenticator.py | 4 ++-- py/selenium/webdriver/remote/errorhandler.py | 3 ++- py/selenium/webdriver/webkitgtk/service.py | 16 ++++++++++------ py/selenium/webdriver/wpewebkit/service.py | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/py/selenium/webdriver/common/virtual_authenticator.py b/py/selenium/webdriver/common/virtual_authenticator.py index 19b0ec615e7c5..4c997629bd4f4 100644 --- a/py/selenium/webdriver/common/virtual_authenticator.py +++ b/py/selenium/webdriver/common/virtual_authenticator.py @@ -80,7 +80,7 @@ def __init__( self, credential_id: bytes, is_resident_credential: bool, - rp_id: str, + rp_id: Optional[str], user_handle: Optional[bytes], private_key: bytes, sign_count: int, @@ -112,7 +112,7 @@ def is_resident_credential(self) -> bool: return self._is_resident_credential @property - def rp_id(self) -> str: + def rp_id(self) -> Optional[str]: return self._rp_id @property diff --git a/py/selenium/webdriver/remote/errorhandler.py b/py/selenium/webdriver/remote/errorhandler.py index 9a100e20543f5..48b4bb584422a 100644 --- a/py/selenium/webdriver/remote/errorhandler.py +++ b/py/selenium/webdriver/remote/errorhandler.py @@ -173,7 +173,8 @@ def check_response(self, response: dict[str, Any]) -> None: message = value.get("value") or value.get("message") if not isinstance(message, str): value = message - message = message.get("message") + if isinstance(message, dict): + message = message.get("message") else: message = value.get("message", None) except ValueError: diff --git a/py/selenium/webdriver/webkitgtk/service.py b/py/selenium/webdriver/webkitgtk/service.py index 5e7d181aa2dcc..e45aa60d2ab35 100644 --- a/py/selenium/webdriver/webkitgtk/service.py +++ b/py/selenium/webdriver/webkitgtk/service.py @@ -18,11 +18,11 @@ import shutil import warnings from collections.abc import Mapping -from typing import Optional, Sequence +from typing import IO, Optional, Sequence from selenium.webdriver.common import service -DEFAULT_EXECUTABLE_PATH: str = shutil.which("WebKitWebDriver") +DEFAULT_EXECUTABLE_PATH: Optional[str] = shutil.which("WebKitWebDriver") class Service(service.Service): @@ -40,7 +40,7 @@ class Service(service.Service): def __init__( self, - executable_path: str = DEFAULT_EXECUTABLE_PATH, + executable_path: Optional[str] = DEFAULT_EXECUTABLE_PATH, port: int = 0, log_path: Optional[str] = None, log_output: Optional[str] = None, @@ -49,15 +49,19 @@ def __init__( **kwargs, ) -> None: self._service_args = list(service_args or []) + + log_file: Optional[IO[bytes]] = None + if log_path is not None: warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2) - log_path = open(log_path, "wb") - log_output = open(log_output, "wb") if log_output else None + log_file = open(log_path, "wb") + elif log_output is not None: + log_file = open(log_output, "wb") super().__init__( executable_path=executable_path, port=port, - log_output=log_path or log_output, + log_output=log_file, env=env, **kwargs, ) diff --git a/py/selenium/webdriver/wpewebkit/service.py b/py/selenium/webdriver/wpewebkit/service.py index 2941633aa91bb..2586ae6619f0f 100644 --- a/py/selenium/webdriver/wpewebkit/service.py +++ b/py/selenium/webdriver/wpewebkit/service.py @@ -39,7 +39,7 @@ class Service(service.Service): def __init__( self, - executable_path: str = DEFAULT_EXECUTABLE_PATH, + executable_path: Optional[str] = DEFAULT_EXECUTABLE_PATH, port: int = 0, log_output: Optional[str] = None, service_args: Optional[Sequence[str]] = None, From 5b0c5134dd440e1df08c168057c0f12a7d0e8cea Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Tue, 21 Oct 2025 16:48:23 +0530 Subject: [PATCH 2/3] Apply suggestions --- py/selenium/webdriver/webkitgtk/service.py | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/py/selenium/webdriver/webkitgtk/service.py b/py/selenium/webdriver/webkitgtk/service.py index e45aa60d2ab35..caa320216c94d 100644 --- a/py/selenium/webdriver/webkitgtk/service.py +++ b/py/selenium/webdriver/webkitgtk/service.py @@ -52,19 +52,27 @@ def __init__( log_file: Optional[IO[bytes]] = None - if log_path is not None: - warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2) - log_file = open(log_path, "wb") - elif log_output is not None: - log_file = open(log_output, "wb") + try: + if log_output is not None: + log_file = open(log_output, "wb") + elif log_path is not None: + warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2) + log_file = open(log_path, "wb") - super().__init__( - executable_path=executable_path, - port=port, - log_output=log_file, - env=env, - **kwargs, - ) + super().__init__( + executable_path=executable_path, + port=port, + log_output=log_file, + env=env, + **kwargs, + ) + except Exception: + if log_file is not None: + try: + log_file.close() + except Exception: + pass + raise def command_line_args(self) -> list[str]: return ["-p", f"{self.port}"] + self._service_args From 17b066c70bd65340c098ba66e51c0ed69c6e12b4 Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Tue, 21 Oct 2025 17:38:08 +0530 Subject: [PATCH 3/3] Resolve merge conflicts with trunk --- py/selenium/webdriver/remote/errorhandler.py | 3 +-- py/selenium/webdriver/webkitgtk/service.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/py/selenium/webdriver/remote/errorhandler.py b/py/selenium/webdriver/remote/errorhandler.py index 48b4bb584422a..5a2b8f038f9b7 100644 --- a/py/selenium/webdriver/remote/errorhandler.py +++ b/py/selenium/webdriver/remote/errorhandler.py @@ -173,8 +173,7 @@ def check_response(self, response: dict[str, Any]) -> None: message = value.get("value") or value.get("message") if not isinstance(message, str): value = message - if isinstance(message, dict): - message = message.get("message") + message = message.get("message") if isinstance(message, dict) else None else: message = value.get("message", None) except ValueError: diff --git a/py/selenium/webdriver/webkitgtk/service.py b/py/selenium/webdriver/webkitgtk/service.py index caa320216c94d..938c0eaa7933a 100644 --- a/py/selenium/webdriver/webkitgtk/service.py +++ b/py/selenium/webdriver/webkitgtk/service.py @@ -17,8 +17,8 @@ import shutil import warnings -from collections.abc import Mapping -from typing import IO, Optional, Sequence +from collections.abc import Mapping, Sequence +from typing import IO, Optional from selenium.webdriver.common import service