Skip to content

Commit 4262d10

Browse files
committed
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. Fixes #15697
1 parent f8c356f commit 4262d10

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

py/selenium/webdriver/common/service.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ def __init__(
5757
driver_path_env_key: Optional[str] = None,
5858
**kwargs,
5959
) -> None:
60+
self.log_output: Optional[Union[int, IOBase]]
6061
if isinstance(log_output, str):
6162
self.log_output = cast(IOBase, open(log_output, "a+", encoding="utf-8"))
6263
elif log_output == subprocess.STDOUT:
63-
self.log_output = cast(Optional[Union[int, IOBase]], None)
64+
self.log_output = None
6465
elif log_output is None or log_output == subprocess.DEVNULL:
65-
self.log_output = cast(Optional[Union[int, IOBase]], subprocess.DEVNULL)
66+
self.log_output = subprocess.DEVNULL
6667
else:
67-
self.log_output = log_output
68+
self.log_output = cast(Union[int, IOBase],log_output)
6869

6970
self.port = port or utils.free_port()
7071
# Default value for every python subprocess: subprocess.Popen(..., creationflags=0)
@@ -208,9 +209,9 @@ def _start_process(self, path: str) -> None:
208209
try:
209210
start_info = None
210211
if system() == "Windows":
211-
start_info = subprocess.STARTUPINFO() # type: ignore[attr-defined]
212-
start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined]
213-
start_info.wShowWindow = subprocess.SW_HIDE # type: ignore[attr-defined]
212+
start_info = subprocess.STARTUPINFO()
213+
start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
214+
start_info.wShowWindow = subprocess.SW_HIDE
214215

215216
self.process = subprocess.Popen(
216217
cmd,

0 commit comments

Comments
 (0)