Skip to content

Commit 9c0a284

Browse files
committed
[py]: Loosen mypy checks; be explicit in service args types and fix some mypy issues
1 parent 118f449 commit 9c0a284

File tree

12 files changed

+36
-32
lines changed

12 files changed

+36
-32
lines changed

py/mypy.ini

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1+
; The aim in future here is we would be able to turn (most) of these flags on, however the typing technical
2+
; debt is quite colossal right now. For now we should maybe get everything working with the config here
3+
; then look at going after partially or completely untyped defs as a phase-2.
14
[mypy]
25
files = selenium
36
; warn about per-module sections in the config file that do not match any files processed.
47
warn_unused_configs = True
58
; disallows subclassing of typing.Any.
6-
disallow_subclassing_any = True
9+
disallow_subclassing_any = False
710
; disallow usage of generic types that do not specify explicit type parameters.
8-
disallow_any_generics = True
11+
disallow_any_generics = False
912
; disallow calling functions without type annotations from functions that have type annotations.
10-
disallow_untyped_calls = True
13+
disallow_untyped_calls = False
1114
; disallow defining functions without type annotations or with incomplete annotations.
12-
disallow_untyped_defs = True
15+
disallow_untyped_defs = False
1316
; disallow defining functions with incomplete type annotations.
14-
disallow_incomplete_defs = True
17+
disallow_incomplete_defs = False
1518
; type-checks the interior of functions without type annotations.
16-
check_untyped_defs = True
19+
check_untyped_defs = False
1720
; reports an error whenever a function with type annotations is decorated with a decorator without annotations.
18-
disallow_untyped_decorators = True
21+
disallow_untyped_decorators = False
1922
; changes the treatment of arguments with a default value of None by not implicitly making their type `typing.Optional`.
20-
no_implicit_optional = True
23+
no_implicit_optional = False
2124
; warns about casting an expression to it's inferred type.
2225
warn_redundant_casts = True
2326
; warns about unneeded `# type: ignore` comments.
2427
warn_unused_ignores = True
2528
; warns when returning a value with typing.Any from a function with a non typing.Any return type.
26-
warn_return_any = True
29+
warn_return_any = False
2730
; Shows a warning when encountering any code inferred to be unreachable after performing type analysis.
28-
warn_unreachable = True
31+
warn_unreachable = False
2932

3033
[mypy-trio_websocket]
3134
; suppress error messages about imports that cannot be resolved.

py/pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ markers =
1212
xfail_safari: Tests expected to fail in Safari
1313
xfail_webkitgtk: Tests expected to fail in webkitgtk
1414
no_driver_after_test: If there are no drivers after the test it will create a new one.
15+
addopts =

py/selenium/webdriver/chrome/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Service(service.ChromiumService):
2727
2828
:param executable_path: install path of the chromedriver executable, defaults to `chromedriver`.
2929
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
30-
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
30+
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
3131
:param log_path: (Optional) String to be passed to the executable as `--log-path`.
3232
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
3333
"""
@@ -36,7 +36,7 @@ def __init__(
3636
self,
3737
executable_path: str = DEFAULT_EXECUTABLE_PATH,
3838
port: int = 0,
39-
service_args: typing.Optional[typing.Sequence[str]] = None,
39+
service_args: typing.Optional[typing.List[str]] = None,
4040
log_path: typing.Optional[str] = None,
4141
env: typing.Optional[typing.Mapping[str, str]] = None,
4242
) -> None:

py/selenium/webdriver/chromium/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ChromiumService(service.Service):
2525
2626
:param executable_path: install path of the executable.
2727
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
28-
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
28+
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
2929
:param log_path: (Optional) String to be passed to the executable as `--log-path`.
3030
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
3131
:param start_error_message: (Optional) Error message that forms part of the error when problems occur
@@ -36,7 +36,7 @@ def __init__(
3636
self,
3737
executable_path: str,
3838
port: int = 0,
39-
service_args: typing.Optional[typing.Sequence[str]] = None,
39+
service_args: typing.Optional[typing.List[str]] = None,
4040
log_path: typing.Optional[str] = None,
4141
env: typing.Optional[typing.Mapping[str, str]] = None,
4242
start_error_message: typing.Optional[str] = None,

py/selenium/webdriver/common/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def __init__(
6565
# Default value for every python subprocess: subprocess.Popen(..., creationflags=0)
6666
self.creation_flags = 0
6767
self.env = env or os.environ
68-
self.process: typing.Optional[subprocess.Popen] = None
6968

7069
@property
7170
def service_url(self) -> str:
@@ -161,7 +160,8 @@ def stop(self) -> None:
161160
if self.log_file != PIPE and not (self.log_file == DEVNULL and _HAS_NATIVE_DEVNULL):
162161
with contextlib.suppress(Exception):
163162
# Todo: Be explicit in what we are catching here.
164-
self.log_file.close()
163+
if hasattr(self.log_file, "close"):
164+
self.log_file.close()
165165

166166
if self.process is not None:
167167
with contextlib.suppress(TypeError):

py/selenium/webdriver/edge/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Service(service.ChromiumService):
3131
:param verbose: (Deprecated) Whether to make the webdriver more verbose (passes the --verbose option to the binary).
3232
Defaults to False.
3333
:param log_path: (Optional) String to be passed to the executable as `--log-path`.
34-
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
34+
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
3535
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
3636
"""
3737

@@ -41,7 +41,7 @@ def __init__(
4141
port: int = 0,
4242
verbose: bool = False,
4343
log_path: typing.Optional[str] = None,
44-
service_args: typing.Optional[typing.Sequence[str]] = None,
44+
service_args: typing.Optional[typing.List[str]] = None,
4545
env: typing.Optional[typing.Mapping[str, str]] = None,
4646
):
4747
self.service_args = service_args or []

py/selenium/webdriver/firefox/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Service(service.Service):
2929
3030
:param executable_path: install path of the geckodriver executable, defaults to `geckodriver`.
3131
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
32-
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
32+
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
3333
:param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler,
3434
defaults to `geckodriver.log`.
3535
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.

py/selenium/webdriver/remote/mobile.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ def context(self):
7171
"""
7272
return self._driver.execute(Command.CURRENT_CONTEXT_HANDLE)
7373

74-
@property
75-
def contexts(self):
76-
"""
77-
returns a list of available contexts
78-
"""
79-
return self._driver.execute(Command.CONTEXT_HANDLES)
80-
8174
@context.setter
8275
def context(self, new_context) -> None:
8376
"""
8477
sets the current context
8578
"""
8679
self._driver.execute(Command.SWITCH_TO_CONTEXT, {"name": new_context})
80+
81+
@property
82+
def contexts(self):
83+
"""
84+
returns a list of available contexts
85+
"""
86+
return self._driver.execute(Command.CONTEXT_HANDLES)

py/selenium/webdriver/safari/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Service(service.Service):
3131
:param executable_path: install path of the safaridriver executable, defaults to `/usr/bin/safaridriver`.
3232
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
3333
:param quiet: Suppress driver stdout & stderr, redirects to os.devnull if enabled.
34-
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
34+
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
3535
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
3636
"""
3737

py/selenium/webdriver/support/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def groups(self) -> Sequence[str]:
9494
if m.match(RGBA_PATTERN, str_):
9595
return cls(*m.groups)
9696
if m.match(RGBA_PCT_PATTERN, str_):
97-
rgba = tuple([float(each) / 100 * 255 for each in m.groups[:3]] + [m.groups[3]]) # type: ignore
97+
rgba = tuple([float(each) / 100 * 255 for each in m.groups[:3]] + [m.groups[3]])
9898
return cls(*rgba)
9999
if m.match(HEX_PATTERN, str_):
100100
rgb = tuple(int(each, 16) for each in m.groups)

0 commit comments

Comments
 (0)