From 4f0434c134cb11f656363cca042b2572a74315e0 Mon Sep 17 00:00:00 2001 From: Saim Date: Sun, 24 Aug 2025 21:20:32 +0530 Subject: [PATCH 1/3] Fix type annotation errors in service.py Fixed the instance variable log_output by properly annotating it as int | IOBase | None. Removed unnecessary #type: ignore comments where mypy requires them. --- py/selenium/webdriver/common/service.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 7dbaaacbf2861..6fd39fc238729 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -57,14 +57,15 @@ def __init__( driver_path_env_key: Optional[str] = None, **kwargs, ) -> None: + self.log_output: Optional[Union[int, IOBase]] if isinstance(log_output, str): self.log_output = cast(IOBase, open(log_output, "a+", encoding="utf-8")) elif log_output == subprocess.STDOUT: - self.log_output = cast(Optional[Union[int, IOBase]], None) + self.log_output = None elif log_output is None or log_output == subprocess.DEVNULL: - self.log_output = cast(Optional[Union[int, IOBase]], subprocess.DEVNULL) + self.log_output = subprocess.DEVNULL else: - self.log_output = log_output + self.log_output = cast(Union[int, IOBase],log_output) self.port = port or utils.free_port() # Default value for every python subprocess: subprocess.Popen(..., creationflags=0) @@ -208,9 +209,9 @@ def _start_process(self, path: str) -> None: try: start_info = None if system() == "Windows": - start_info = subprocess.STARTUPINFO() # type: ignore[attr-defined] - start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined] - start_info.wShowWindow = subprocess.SW_HIDE # type: ignore[attr-defined] + start_info = subprocess.STARTUPINFO() + start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW + start_info.wShowWindow = subprocess.SW_HIDE self.process = subprocess.Popen( cmd, From 1209a02cd5fde1b4ee7ae0868c136c5813da8adf Mon Sep 17 00:00:00 2001 From: Saim Date: Mon, 25 Aug 2025 15:32:56 +0530 Subject: [PATCH 2/3] reformatted using ruff format --- py/selenium/webdriver/common/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 6fd39fc238729..02ddfdcfe7d5e 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -65,7 +65,7 @@ def __init__( elif log_output is None or log_output == subprocess.DEVNULL: self.log_output = subprocess.DEVNULL else: - self.log_output = cast(Union[int, IOBase],log_output) + self.log_output = cast(Union[int, IOBase], log_output) self.port = port or utils.free_port() # Default value for every python subprocess: subprocess.Popen(..., creationflags=0) From 83233b3dc6df4a9114fae8dc15cfa7a0601403e6 Mon Sep 17 00:00:00 2001 From: Saim Date: Mon, 25 Aug 2025 18:07:50 +0530 Subject: [PATCH 3/3] Reverted the type-ignore comment removal --- py/selenium/webdriver/common/service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 02ddfdcfe7d5e..7b3bdf81c403a 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -209,9 +209,9 @@ def _start_process(self, path: str) -> None: try: start_info = None if system() == "Windows": - start_info = subprocess.STARTUPINFO() - start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW - start_info.wShowWindow = subprocess.SW_HIDE + start_info = subprocess.STARTUPINFO() # type: ignore[attr-defined] + start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined] + start_info.wShowWindow = subprocess.SW_HIDE # type: ignore[attr-defined] self.process = subprocess.Popen( cmd,