You've already forked SeleniumHQ.selenium.py
[py]: Loosen mypy
checks; be explicit in service args types and fix some mypy issues
NOKEYCHECK=True GitOrigin-RevId: 9c0a284f30b96003fc60cdf3eefe679280a54ab5
This commit is contained in:
mypy.inipytest.ini
selenium/webdriver
chrome
chromium
common
edge
firefox
remote
safari
support
webkitgtk
wpewebkit
23
mypy.ini
23
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.
|
||||
|
@ -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 =
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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):
|
||||
|
@ -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 []
|
||||
|
@ -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`.
|
||||
|
@ -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)
|
||||
|
@ -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`.
|
||||
"""
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 []
|
||||
|
@ -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 []
|
||||
|
Reference in New Issue
Block a user