From 2694307e01eb8cae8ada079b3bcd2e6d154217a2 Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Fri, 20 Jun 2025 17:53:33 -0500 Subject: [PATCH 1/6] addressing mypy errors --- py/selenium/webdriver/chrome/service.py | 8 ++++---- py/selenium/webdriver/chrome/webdriver.py | 3 +++ py/selenium/webdriver/chromium/service.py | 10 ++++++---- py/selenium/webdriver/chromium/webdriver.py | 13 ++++++------- py/selenium/webdriver/common/service.py | 2 ++ py/selenium/webdriver/edge/service.py | 6 +++--- py/selenium/webdriver/edge/webdriver.py | 3 +++ 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/py/selenium/webdriver/chrome/service.py b/py/selenium/webdriver/chrome/service.py index bc6d3f00fb1e9..15c71ca9f641b 100644 --- a/py/selenium/webdriver/chrome/service.py +++ b/py/selenium/webdriver/chrome/service.py @@ -33,12 +33,12 @@ class Service(service.ChromiumService): :param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ - + _service_args: list[str] def __init__( self, executable_path: Optional[str] = None, port: int = 0, - service_args: Optional[Sequence[str]] = None, + service_args: Optional[list[str]] = None, log_output: Optional[SubprocessStdAlias] = None, env: Optional[Mapping[str, str]] = None, **kwargs, @@ -55,11 +55,11 @@ def __init__( ) @property - def service_args(self) -> Sequence[str]: + def service_args(self) -> list[str]: return self._service_args @service_args.setter - def service_args(self, value: Sequence[str]): + def service_args(self, value: list[str]): if isinstance(value, str) or not isinstance(value, Sequence): raise TypeError("service_args must be a sequence") self._service_args = list(value) diff --git a/py/selenium/webdriver/chrome/webdriver.py b/py/selenium/webdriver/chrome/webdriver.py index 15f4aeaf6094e..006050a883dc3 100644 --- a/py/selenium/webdriver/chrome/webdriver.py +++ b/py/selenium/webdriver/chrome/webdriver.py @@ -27,6 +27,9 @@ class WebDriver(ChromiumDriver): """Controls the ChromeDriver and allows you to drive the browser.""" + options: Options + service: Service + def __init__( self, options: Optional[Options] = None, diff --git a/py/selenium/webdriver/chromium/service.py b/py/selenium/webdriver/chromium/service.py index 80c79c56ca993..d08cbd5272438 100644 --- a/py/selenium/webdriver/chromium/service.py +++ b/py/selenium/webdriver/chromium/service.py @@ -17,7 +17,7 @@ from collections.abc import Mapping, Sequence from io import IOBase -from typing import Optional +from typing import Optional, Union from selenium.types import SubprocessStdAlias from selenium.webdriver.common import service @@ -34,12 +34,14 @@ class ChromiumService(service.Service): :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. :param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable. """ + _service_args: list[str] + log_output: Union[Optional[IOBase], Optional[Union[int, IOBase]], Optional[SubprocessStdAlias]] def __init__( self, executable_path: Optional[str] = None, port: int = 0, - service_args: Optional[Sequence[str]] = None, + service_args: Optional[list[str]] = None, log_output: Optional[SubprocessStdAlias] = None, env: Optional[Mapping[str, str]] = None, driver_path_env_key: Optional[str] = None, @@ -69,11 +71,11 @@ def command_line_args(self) -> list[str]: return [f"--port={self.port}"] + self._service_args @property - def service_args(self) -> Sequence[str]: + def service_args(self) -> list[str]: return self._service_args @service_args.setter - def service_args(self, value: Sequence[str]): + def service_args(self, value: list[str]): if isinstance(value, str) or not isinstance(value, Sequence): raise TypeError("service_args must be a sequence") self._service_args = list(value) diff --git a/py/selenium/webdriver/chromium/webdriver.py b/py/selenium/webdriver/chromium/webdriver.py index 4dcf8d73e8fe0..b6e7427f12aef 100644 --- a/py/selenium/webdriver/chromium/webdriver.py +++ b/py/selenium/webdriver/chromium/webdriver.py @@ -15,12 +15,11 @@ # specific language governing permissions and limitations # under the License. -from typing import Optional +from selenium.webdriver.chromium.options import ChromiumOptions from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection +from selenium.webdriver.chromium.service import ChromiumService from selenium.webdriver.common.driver_finder import DriverFinder -from selenium.webdriver.common.options import ArgOptions -from selenium.webdriver.common.service import Service from selenium.webdriver.remote.command import Command from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver @@ -31,10 +30,10 @@ class ChromiumDriver(RemoteWebDriver): def __init__( self, - browser_name: Optional[str] = None, - vendor_prefix: Optional[str] = None, - options: ArgOptions = ArgOptions(), - service: Optional[Service] = None, + browser_name: str, + vendor_prefix: str, + options: ChromiumOptions = ChromiumOptions(), + service: ChromiumService = ChromiumService(), keep_alive: bool = True, ) -> None: """Creates a new WebDriver instance of the ChromiumDriver. Starts the diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 7dbaaacbf2861..33349a0e4f38f 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -48,6 +48,8 @@ class Service(ABC): :param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable. """ + log_output: Union[Optional[IOBase], Optional[Union[int, IOBase]], Optional[SubprocessStdAlias]] + def __init__( self, executable_path: Optional[str] = None, diff --git a/py/selenium/webdriver/edge/service.py b/py/selenium/webdriver/edge/service.py index ef53f24d8f86b..af43a2f76e475 100644 --- a/py/selenium/webdriver/edge/service.py +++ b/py/selenium/webdriver/edge/service.py @@ -39,7 +39,7 @@ def __init__( executable_path: Optional[str] = None, port: int = 0, log_output: Optional[SubprocessStdAlias] = None, - service_args: Optional[Sequence[str]] = None, + service_args: Optional[list[str]] = None, env: Optional[Mapping[str, str]] = None, driver_path_env_key: Optional[str] = None, **kwargs, @@ -58,11 +58,11 @@ def __init__( ) @property - def service_args(self) -> Sequence[str]: + def service_args(self) -> list[str]: return self._service_args @service_args.setter - def service_args(self, value: Sequence[str]): + def service_args(self, value: list[str]): if isinstance(value, str) or not isinstance(value, Sequence): raise TypeError("service_args must be a sequence") self._service_args = list(value) diff --git a/py/selenium/webdriver/edge/webdriver.py b/py/selenium/webdriver/edge/webdriver.py index 5b7b1856dfc08..dc3a70d586c56 100644 --- a/py/selenium/webdriver/edge/webdriver.py +++ b/py/selenium/webdriver/edge/webdriver.py @@ -27,6 +27,9 @@ class WebDriver(ChromiumDriver): """Controls the MSEdgeDriver and allows you to drive the browser.""" + options: Options + service: Service + def __init__( self, options: Optional[Options] = None, From d3cc86a0adbc5cd6557c11bc73101a11759f81c0 Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Fri, 20 Jun 2025 18:37:58 -0500 Subject: [PATCH 2/6] using PR code suggestion for cleaner annotation --- py/selenium/webdriver/chromium/service.py | 3 ++- py/selenium/webdriver/common/service.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/py/selenium/webdriver/chromium/service.py b/py/selenium/webdriver/chromium/service.py index d08cbd5272438..0c37c4ef59821 100644 --- a/py/selenium/webdriver/chromium/service.py +++ b/py/selenium/webdriver/chromium/service.py @@ -34,8 +34,9 @@ class ChromiumService(service.Service): :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. :param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable. """ + _service_args: list[str] - log_output: Union[Optional[IOBase], Optional[Union[int, IOBase]], Optional[SubprocessStdAlias]] + log_output: Union[None, IOBase, int, SubprocessStdAlias] def __init__( self, diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 33349a0e4f38f..1a9e8b96099cc 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -48,7 +48,7 @@ class Service(ABC): :param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable. """ - log_output: Union[Optional[IOBase], Optional[Union[int, IOBase]], Optional[SubprocessStdAlias]] + log_output: Union[None, IOBase, int, SubprocessStdAlias] def __init__( self, From 9687595f287c30f0a3d7f96fbb7d19305d19ac1e Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Mon, 23 Jun 2025 10:02:15 -0500 Subject: [PATCH 3/6] reverting argument annotation since we convert anything passed in to a list. --- py/selenium/webdriver/chrome/service.py | 6 ++++-- py/selenium/webdriver/chromium/service.py | 2 +- py/selenium/webdriver/edge/service.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/py/selenium/webdriver/chrome/service.py b/py/selenium/webdriver/chrome/service.py index 15c71ca9f641b..cb7096ff39753 100644 --- a/py/selenium/webdriver/chrome/service.py +++ b/py/selenium/webdriver/chrome/service.py @@ -33,17 +33,19 @@ class Service(service.ChromiumService): :param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ + _service_args: list[str] + def __init__( self, executable_path: Optional[str] = None, port: int = 0, - service_args: Optional[list[str]] = None, + service_args: Optional[Sequence[str]] = None, log_output: Optional[SubprocessStdAlias] = None, env: Optional[Mapping[str, str]] = None, **kwargs, ) -> None: - self._service_args = service_args or [] + self._service_args = list(service_args or []) super().__init__( executable_path=executable_path, diff --git a/py/selenium/webdriver/chromium/service.py b/py/selenium/webdriver/chromium/service.py index 0c37c4ef59821..8c0f5873379c7 100644 --- a/py/selenium/webdriver/chromium/service.py +++ b/py/selenium/webdriver/chromium/service.py @@ -42,7 +42,7 @@ def __init__( self, executable_path: Optional[str] = None, port: int = 0, - service_args: Optional[list[str]] = None, + service_args: Optional[Sequence[str]] = None, log_output: Optional[SubprocessStdAlias] = None, env: Optional[Mapping[str, str]] = None, driver_path_env_key: Optional[str] = None, diff --git a/py/selenium/webdriver/edge/service.py b/py/selenium/webdriver/edge/service.py index af43a2f76e475..5828a6c3719bb 100644 --- a/py/selenium/webdriver/edge/service.py +++ b/py/selenium/webdriver/edge/service.py @@ -39,7 +39,7 @@ def __init__( executable_path: Optional[str] = None, port: int = 0, log_output: Optional[SubprocessStdAlias] = None, - service_args: Optional[list[str]] = None, + service_args: Optional[Sequence[str]] = None, env: Optional[Mapping[str, str]] = None, driver_path_env_key: Optional[str] = None, **kwargs, From 95040171b5c39cd3a65c4d0d90a19088374b0f0f Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Mon, 23 Jun 2025 10:02:44 -0500 Subject: [PATCH 4/6] adding similar changes to wpewebkit --- py/selenium/webdriver/wpewebkit/service.py | 2 ++ py/selenium/webdriver/wpewebkit/webdriver.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/py/selenium/webdriver/wpewebkit/service.py b/py/selenium/webdriver/wpewebkit/service.py index 2ad99e77a54a6..7491ad6805db6 100644 --- a/py/selenium/webdriver/wpewebkit/service.py +++ b/py/selenium/webdriver/wpewebkit/service.py @@ -37,6 +37,8 @@ class Service(service.Service): :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ + _service_args: list[str] + def __init__( self, executable_path: str = DEFAULT_EXECUTABLE_PATH, diff --git a/py/selenium/webdriver/wpewebkit/webdriver.py b/py/selenium/webdriver/wpewebkit/webdriver.py index 64e298cc475c5..8ef9e4cd58ddc 100644 --- a/py/selenium/webdriver/wpewebkit/webdriver.py +++ b/py/selenium/webdriver/wpewebkit/webdriver.py @@ -28,9 +28,11 @@ class WebDriver(RemoteWebDriver): """Controls the WPEWebKitDriver and allows you to drive the browser.""" + service: Service + def __init__( self, - options=None, + options: Optional[Options] = None, service: Optional[Service] = None, ): """Creates a new instance of the WPEWebKit driver. From 926aafbd0e1fd34a70ab0f66f2b7dde69dea47d0 Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Mon, 23 Jun 2025 10:03:07 -0500 Subject: [PATCH 5/6] removing extra annotation --- py/selenium/webdriver/chrome/webdriver.py | 1 - 1 file changed, 1 deletion(-) diff --git a/py/selenium/webdriver/chrome/webdriver.py b/py/selenium/webdriver/chrome/webdriver.py index 006050a883dc3..55ae7c2fce9a5 100644 --- a/py/selenium/webdriver/chrome/webdriver.py +++ b/py/selenium/webdriver/chrome/webdriver.py @@ -27,7 +27,6 @@ class WebDriver(ChromiumDriver): """Controls the ChromeDriver and allows you to drive the browser.""" - options: Options service: Service def __init__( From 42d39fd8b2705afb0427574fda7571d4d387642e Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Mon, 23 Jun 2025 10:12:00 -0500 Subject: [PATCH 6/6] removing extra annotation --- py/selenium/webdriver/edge/webdriver.py | 1 - 1 file changed, 1 deletion(-) diff --git a/py/selenium/webdriver/edge/webdriver.py b/py/selenium/webdriver/edge/webdriver.py index dc3a70d586c56..afab6eb15e1ca 100644 --- a/py/selenium/webdriver/edge/webdriver.py +++ b/py/selenium/webdriver/edge/webdriver.py @@ -27,7 +27,6 @@ class WebDriver(ChromiumDriver): """Controls the MSEdgeDriver and allows you to drive the browser.""" - options: Options service: Service def __init__(