diff --git a/mypy.ini b/mypy.ini index 50301890..9ccefe45 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,31 +1,34 @@ +; The aim in future here is we would be able to turn (most) of these flags on, however the typing technical +; debt is quite colossal right now. For now we should maybe get everything working with the config here +; then look at going after partially or completely untyped defs as a phase-2. [mypy] files = selenium ; warn about per-module sections in the config file that do not match any files processed. warn_unused_configs = True ; disallows subclassing of typing.Any. -disallow_subclassing_any = True +disallow_subclassing_any = False ; disallow usage of generic types that do not specify explicit type parameters. -disallow_any_generics = True +disallow_any_generics = False ; disallow calling functions without type annotations from functions that have type annotations. -disallow_untyped_calls = True +disallow_untyped_calls = False ; disallow defining functions without type annotations or with incomplete annotations. -disallow_untyped_defs = True +disallow_untyped_defs = False ; disallow defining functions with incomplete type annotations. -disallow_incomplete_defs = True +disallow_incomplete_defs = False ; type-checks the interior of functions without type annotations. -check_untyped_defs = True +check_untyped_defs = False ; reports an error whenever a function with type annotations is decorated with a decorator without annotations. -disallow_untyped_decorators = True +disallow_untyped_decorators = False ; changes the treatment of arguments with a default value of None by not implicitly making their type `typing.Optional`. -no_implicit_optional = True +no_implicit_optional = False ; warns about casting an expression to it's inferred type. warn_redundant_casts = True ; warns about unneeded `# type: ignore` comments. warn_unused_ignores = True ; warns when returning a value with typing.Any from a function with a non typing.Any return type. -warn_return_any = True +warn_return_any = False ; Shows a warning when encountering any code inferred to be unreachable after performing type analysis. -warn_unreachable = True +warn_unreachable = False [mypy-trio_websocket] ; suppress error messages about imports that cannot be resolved. diff --git a/pytest.ini b/pytest.ini index 844102c2..e84b365d 100644 --- a/pytest.ini +++ b/pytest.ini @@ -12,3 +12,4 @@ markers = xfail_safari: Tests expected to fail in Safari xfail_webkitgtk: Tests expected to fail in webkitgtk no_driver_after_test: If there are no drivers after the test it will create a new one. +addopts = diff --git a/selenium/webdriver/chrome/service.py b/selenium/webdriver/chrome/service.py index 3eb57e49..76b10a31 100644 --- a/selenium/webdriver/chrome/service.py +++ b/selenium/webdriver/chrome/service.py @@ -27,7 +27,7 @@ class Service(service.ChromiumService): :param executable_path: install path of the chromedriver executable, defaults to `chromedriver`. :param port: Port for the service to run on, defaults to 0 where the operating system will decide. - :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. :param log_path: (Optional) String to be passed to the executable as `--log-path`. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ @@ -36,7 +36,7 @@ class Service(service.ChromiumService): self, executable_path: str = DEFAULT_EXECUTABLE_PATH, port: int = 0, - service_args: typing.Optional[typing.Sequence[str]] = None, + service_args: typing.Optional[typing.List[str]] = None, log_path: typing.Optional[str] = None, env: typing.Optional[typing.Mapping[str, str]] = None, ) -> None: diff --git a/selenium/webdriver/chromium/service.py b/selenium/webdriver/chromium/service.py index b57180d5..6e005ab1 100644 --- a/selenium/webdriver/chromium/service.py +++ b/selenium/webdriver/chromium/service.py @@ -25,7 +25,7 @@ class ChromiumService(service.Service): :param executable_path: install path of the executable. :param port: Port for the service to run on, defaults to 0 where the operating system will decide. - :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. :param log_path: (Optional) String to be passed to the executable as `--log-path`. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. :param start_error_message: (Optional) Error message that forms part of the error when problems occur @@ -36,7 +36,7 @@ class ChromiumService(service.Service): self, executable_path: str, port: int = 0, - service_args: typing.Optional[typing.Sequence[str]] = None, + service_args: typing.Optional[typing.List[str]] = None, log_path: typing.Optional[str] = None, env: typing.Optional[typing.Mapping[str, str]] = None, start_error_message: typing.Optional[str] = None, diff --git a/selenium/webdriver/common/service.py b/selenium/webdriver/common/service.py index d73c6fab..cba23473 100644 --- a/selenium/webdriver/common/service.py +++ b/selenium/webdriver/common/service.py @@ -65,7 +65,6 @@ class Service(ABC): # Default value for every python subprocess: subprocess.Popen(..., creationflags=0) self.creation_flags = 0 self.env = env or os.environ - self.process: typing.Optional[subprocess.Popen] = None @property def service_url(self) -> str: @@ -161,7 +160,8 @@ class Service(ABC): if self.log_file != PIPE and not (self.log_file == DEVNULL and _HAS_NATIVE_DEVNULL): with contextlib.suppress(Exception): # Todo: Be explicit in what we are catching here. - self.log_file.close() + if hasattr(self.log_file, "close"): + self.log_file.close() if self.process is not None: with contextlib.suppress(TypeError): diff --git a/selenium/webdriver/edge/service.py b/selenium/webdriver/edge/service.py index d8ec2aa6..603dc1e3 100644 --- a/selenium/webdriver/edge/service.py +++ b/selenium/webdriver/edge/service.py @@ -31,7 +31,7 @@ class Service(service.ChromiumService): :param verbose: (Deprecated) Whether to make the webdriver more verbose (passes the --verbose option to the binary). Defaults to False. :param log_path: (Optional) String to be passed to the executable as `--log-path`. - :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ @@ -41,7 +41,7 @@ class Service(service.ChromiumService): port: int = 0, verbose: bool = False, log_path: typing.Optional[str] = None, - service_args: typing.Optional[typing.Sequence[str]] = None, + service_args: typing.Optional[typing.List[str]] = None, env: typing.Optional[typing.Mapping[str, str]] = None, ): self.service_args = service_args or [] diff --git a/selenium/webdriver/firefox/service.py b/selenium/webdriver/firefox/service.py index cca3cd1a..b1aaaed5 100644 --- a/selenium/webdriver/firefox/service.py +++ b/selenium/webdriver/firefox/service.py @@ -29,7 +29,7 @@ class Service(service.Service): :param executable_path: install path of the geckodriver executable, defaults to `geckodriver`. :param port: Port for the service to run on, defaults to 0 where the operating system will decide. - :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. :param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler, defaults to `geckodriver.log`. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. diff --git a/selenium/webdriver/remote/mobile.py b/selenium/webdriver/remote/mobile.py index d57b3440..8798ce58 100644 --- a/selenium/webdriver/remote/mobile.py +++ b/selenium/webdriver/remote/mobile.py @@ -71,16 +71,16 @@ class Mobile: """ return self._driver.execute(Command.CURRENT_CONTEXT_HANDLE) - @property - def contexts(self): - """ - returns a list of available contexts - """ - return self._driver.execute(Command.CONTEXT_HANDLES) - @context.setter def context(self, new_context) -> None: """ sets the current context """ self._driver.execute(Command.SWITCH_TO_CONTEXT, {"name": new_context}) + + @property + def contexts(self): + """ + returns a list of available contexts + """ + return self._driver.execute(Command.CONTEXT_HANDLES) diff --git a/selenium/webdriver/safari/service.py b/selenium/webdriver/safari/service.py index f21c4493..c32d3b1d 100644 --- a/selenium/webdriver/safari/service.py +++ b/selenium/webdriver/safari/service.py @@ -31,7 +31,7 @@ class Service(service.Service): :param executable_path: install path of the safaridriver executable, defaults to `/usr/bin/safaridriver`. :param port: Port for the service to run on, defaults to 0 where the operating system will decide. :param quiet: Suppress driver stdout & stderr, redirects to os.devnull if enabled. - :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ diff --git a/selenium/webdriver/support/color.py b/selenium/webdriver/support/color.py index f9c9adf1..a9616c1f 100644 --- a/selenium/webdriver/support/color.py +++ b/selenium/webdriver/support/color.py @@ -94,7 +94,7 @@ class Color: if m.match(RGBA_PATTERN, str_): return cls(*m.groups) if m.match(RGBA_PCT_PATTERN, str_): - rgba = tuple([float(each) / 100 * 255 for each in m.groups[:3]] + [m.groups[3]]) # type: ignore + rgba = tuple([float(each) / 100 * 255 for each in m.groups[:3]] + [m.groups[3]]) return cls(*rgba) if m.match(HEX_PATTERN, str_): rgb = tuple(int(each, 16) for each in m.groups) diff --git a/selenium/webdriver/webkitgtk/service.py b/selenium/webdriver/webkitgtk/service.py index 8dfbf38f..2a71c398 100644 --- a/selenium/webdriver/webkitgtk/service.py +++ b/selenium/webdriver/webkitgtk/service.py @@ -27,7 +27,7 @@ class Service(service.Service): :param executable_path: install path of the WebKitWebDriver executable, defaults to `WebKitWebDriver`. :param port: Port for the service to run on, defaults to 0 where the operating system will decide. - :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. :param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ @@ -37,7 +37,7 @@ class Service(service.Service): executable_path: str = DEFAULT_EXECUTABLE_PATH, port: int = 0, log_path: typing.Optional[str] = None, - service_args: typing.Optional[typing.Sequence[str]] = None, + service_args: typing.Optional[typing.List[str]] = None, env: typing.Optional[typing.Mapping[str, str]] = None, ): self.service_args = service_args or [] diff --git a/selenium/webdriver/wpewebkit/service.py b/selenium/webdriver/wpewebkit/service.py index 3b5b0b3a..e188739e 100644 --- a/selenium/webdriver/wpewebkit/service.py +++ b/selenium/webdriver/wpewebkit/service.py @@ -27,7 +27,7 @@ class Service(service.Service): :param executable_path: install path of the WPEWebDriver executable, defaults to `WPEWebDriver`. :param port: Port for the service to run on, defaults to 0 where the operating system will decide. - :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. :param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ @@ -37,7 +37,7 @@ class Service(service.Service): executable_path: str = DEFAULT_EXECUTABLE_PATH, port: int = 0, log_path: typing.Optional[str] = None, - service_args: typing.Optional[typing.Sequence[str]] = None, + service_args: typing.Optional[typing.List[str]] = None, env: typing.Optional[typing.Mapping[str, str]] = None, ): self.service_args = service_args or []