diff --git a/py/generate.py b/py/generate.py index 026e80673b40f..0763084423168 100644 --- a/py/generate.py +++ b/py/generate.py @@ -36,7 +36,7 @@ from pathlib import Path import re from textwrap import dedent, indent as tw_indent -import typing +from typing import Optional , cast, List, Union, Iterator import inflection # type: ignore @@ -206,11 +206,11 @@ def from_json(cls, type): class CdpProperty: ''' A property belonging to a non-primitive CDP type. ''' name: str - description: typing.Optional[str] - type: typing.Optional[str] - ref: typing.Optional[str] - enum: typing.List[str] - items: typing.Optional[CdpItems] + description: Optional[str] + type: Optional[str] + ref: Optional[str] + enum: List[str] + items: Optional[CdpItems] optional: bool experimental: bool deprecated: bool @@ -236,7 +236,7 @@ def py_annotation(self): ann = py_ref else: ann = CdpPrimitiveType.get_annotation( - typing.cast(str, self.type)) + cast(str, self.type)) if self.optional: ann = f'typing.Optional[{ann}]' return ann @@ -316,11 +316,11 @@ def generate_from_json(self, dict_): class CdpType: ''' A top-level CDP type. ''' id: str - description: typing.Optional[str] + description: Optional[str] type: str - items: typing.Optional[CdpItems] - enum: typing.List[str] - properties: typing.List[CdpProperty] + items: Optional[CdpItems] + enum: List[str] + properties: List[CdpProperty] @classmethod def from_json(cls, type_): @@ -500,7 +500,7 @@ def generate_code(self): py_type = f"{ref_to_python(self.ref)}" else: py_type = CdpPrimitiveType.get_annotation( - typing.cast(str, self.type)) + cast(str, self.type)) if self.optional: py_type = f'typing.Optional[{py_type}]' code = f"{self.py_name}: {py_type}" @@ -585,8 +585,8 @@ class CdpCommand: description: str experimental: bool deprecated: bool - parameters: typing.List[CdpParameter] - returns: typing.List[CdpReturn] + parameters: List[CdpParameter] + returns: List[CdpReturn] domain: str @property @@ -605,8 +605,8 @@ def from_json(cls, command, domain) -> 'CdpCommand': command.get('description'), command.get('experimental', False), command.get('deprecated', False), - [typing.cast(CdpParameter, CdpParameter.from_json(p)) for p in parameters], - [typing.cast(CdpReturn, CdpReturn.from_json(r)) for r in returns], + [cast(CdpParameter, CdpParameter.from_json(p)) for p in parameters], + [cast(CdpReturn, CdpReturn.from_json(r)) for r in returns], domain, ) @@ -712,10 +712,10 @@ def get_refs(self): class CdpEvent: ''' A CDP event object. ''' name: str - description: typing.Optional[str] + description: Optional[str] deprecated: bool experimental: bool - parameters: typing.List[CdpParameter] + parameters: List[CdpParameter] domain: str @property @@ -731,7 +731,7 @@ def from_json(cls, json: dict, domain: str): json.get('description'), json.get('deprecated', False), json.get('experimental', False), - [typing.cast(CdpParameter, CdpParameter.from_json(p)) + [cast(CdpParameter, CdpParameter.from_json(p)) for p in json.get('parameters', [])], domain ) @@ -786,12 +786,12 @@ def get_refs(self): class CdpDomain: ''' A CDP domain contains metadata, types, commands, and events. ''' domain: str - description: typing.Optional[str] + description: Optional[str] experimental: bool - dependencies: typing.List[str] - types: typing.List[CdpType] - commands: typing.List[CdpCommand] - events: typing.List[CdpEvent] + dependencies: List[str] + types: List[CdpType] + commands: List[CdpCommand] + events: List[CdpEvent] @property def module(self): @@ -826,8 +826,8 @@ def generate_code(self): code += import_code code += '\n\n' code += '\n' - item_iter_t = typing.Union[CdpEvent, CdpCommand, CdpType] - item_iter: typing.Iterator[item_iter_t] = itertools.chain( + item_iter_t = Union[CdpEvent, CdpCommand, CdpType] + item_iter: Iterator[item_iter_t] = itertools.chain( iter(self.types), iter(self.commands), iter(self.events), diff --git a/py/selenium/types.py b/py/selenium/types.py index a776904b4a4bd..f055ea1452fff 100644 --- a/py/selenium/types.py +++ b/py/selenium/types.py @@ -16,10 +16,14 @@ # under the License. """Selenium type definitions.""" -import typing +from typing import IO +from typing import Any +from typing import Iterable +from typing import Type +from typing import Union -AnyKey = typing.Union[str, int, float] -WaitExcTypes = typing.Iterable[typing.Type[Exception]] +AnyKey = Union[str, int, float] +WaitExcTypes = Iterable[Type[Exception]] # Service Types -SubprocessStdAlias = typing.Union[int, str, typing.IO[typing.Any]] +SubprocessStdAlias = Union[int, str, IO[Any]] diff --git a/py/selenium/webdriver/chrome/service.py b/py/selenium/webdriver/chrome/service.py index e151f768d5618..40f94841b2304 100644 --- a/py/selenium/webdriver/chrome/service.py +++ b/py/selenium/webdriver/chrome/service.py @@ -14,7 +14,11 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing + + +from typing import List +from typing import Mapping +from typing import Optional from selenium.types import SubprocessStdAlias from selenium.webdriver.chromium import service @@ -35,9 +39,9 @@ def __init__( self, executable_path=None, port: int = 0, - service_args: typing.Optional[typing.List[str]] = None, + service_args: Optional[List[str]] = None, log_output: SubprocessStdAlias = None, - env: typing.Optional[typing.Mapping[str, str]] = None, + env: Optional[Mapping[str, str]] = None, **kwargs, ) -> None: super().__init__( diff --git a/py/selenium/webdriver/chromium/service.py b/py/selenium/webdriver/chromium/service.py index aebedec40f509..f6c71e3ba719a 100644 --- a/py/selenium/webdriver/chromium/service.py +++ b/py/selenium/webdriver/chromium/service.py @@ -14,8 +14,10 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing from io import IOBase +from typing import List +from typing import Mapping +from typing import Optional from selenium.types import SubprocessStdAlias from selenium.webdriver.common import service @@ -36,9 +38,9 @@ def __init__( self, executable_path: str = None, port: int = 0, - service_args: typing.Optional[typing.List[str]] = None, + service_args: Optional[List[str]] = None, log_output: SubprocessStdAlias = None, - env: typing.Optional[typing.Mapping[str, str]] = None, + env: Optional[Mapping[str, str]] = None, driver_path_env_key: str = None, **kwargs, ) -> None: @@ -47,7 +49,7 @@ def __init__( if isinstance(log_output, str): self.service_args.append(f"--log-path={log_output}") - self.log_output: typing.Optional[IOBase] = None + self.log_output: Optional[IOBase] = None elif isinstance(log_output, IOBase): self.log_output = log_output else: @@ -62,5 +64,5 @@ def __init__( **kwargs, ) - def command_line_args(self) -> typing.List[str]: + def command_line_args(self) -> List[str]: return [f"--port={self.port}"] + self.service_args diff --git a/py/selenium/webdriver/common/actions/pointer_input.py b/py/selenium/webdriver/common/actions/pointer_input.py index ce5e1c53c91f9..0d7e7a87188c1 100644 --- a/py/selenium/webdriver/common/actions/pointer_input.py +++ b/py/selenium/webdriver/common/actions/pointer_input.py @@ -14,7 +14,10 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing + +from typing import Any +from typing import Dict +from typing import Optional from typing import Union from selenium.common.exceptions import InvalidArgumentException @@ -41,7 +44,7 @@ def create_pointer_move( duration=DEFAULT_MOVE_DURATION, x: float = 0, y: float = 0, - origin: typing.Optional[WebElement] = None, + origin: Optional[WebElement] = None, **kwargs, ): action = {"type": "pointerMove", "duration": duration, "x": x, "y": y, **kwargs} @@ -67,7 +70,7 @@ def create_pause(self, pause_duration: Union[int, float] = 0) -> None: def encode(self): return {"type": self.type, "parameters": {"pointerType": self.kind}, "id": self.name, "actions": self.actions} - def _convert_keys(self, actions: typing.Dict[str, typing.Any]): + def _convert_keys(self, actions: Dict[str, Any]): out = {} for k, v in actions.items(): if v is None: diff --git a/py/selenium/webdriver/common/bidi/cdp.py b/py/selenium/webdriver/common/bidi/cdp.py index c9ed47825e4da..2d40ed9ddc66e 100644 --- a/py/selenium/webdriver/common/bidi/cdp.py +++ b/py/selenium/webdriver/common/bidi/cdp.py @@ -30,18 +30,23 @@ import json import logging import pathlib -import typing from collections import defaultdict from contextlib import asynccontextmanager from contextlib import contextmanager from dataclasses import dataclass +from typing import Any +from typing import AsyncGenerator +from typing import AsyncIterator +from typing import Generator +from typing import Type +from typing import TypeVar import trio from trio_websocket import ConnectionClosed as WsConnectionClosed from trio_websocket import connect_websocket_url logger = logging.getLogger("trio_cdp") -T = typing.TypeVar("T") +T = TypeVar("T") MAX_WS_MESSAGE_SIZE = 2**24 devtools = None @@ -184,7 +189,7 @@ class CmEventProxy: value set that contains the returned event. """ - value: typing.Any = None + value: Any = None class CdpBase: @@ -197,7 +202,7 @@ def __init__(self, ws, session_id, target_id): self.inflight_cmd = {} self.inflight_result = {} - async def execute(self, cmd: typing.Generator[dict, T, typing.Any]) -> T: + async def execute(self, cmd: Generator[dict, T, Any]) -> T: """Execute a command on the server and wait for the result. :param cmd: any CDP command @@ -236,7 +241,7 @@ def listen(self, *event_types, buffer_size=10): return receiver @asynccontextmanager - async def wait_for(self, event_type: typing.Type[T], buffer_size=10) -> typing.AsyncGenerator[CmEventProxy, None]: + async def wait_for(self, event_type: Type[T], buffer_size=10) -> AsyncGenerator[CmEventProxy, None]: """Wait for an event of the given type and return it. This is an async context manager, so you should open it inside @@ -406,7 +411,7 @@ async def aclose(self): await self.ws.aclose() @asynccontextmanager - async def open_session(self, target_id) -> typing.AsyncIterator[CdpSession]: + async def open_session(self, target_id) -> AsyncIterator[CdpSession]: """This context manager opens a session and enables the "simple" style of calling CDP APIs. @@ -468,7 +473,7 @@ async def _reader_task(self): @asynccontextmanager -async def open_cdp(url) -> typing.AsyncIterator[CdpConnection]: +async def open_cdp(url) -> AsyncIterator[CdpConnection]: """This async context manager opens a connection to the browser specified by ``url`` before entering the block, then closes the connection when the block exits. diff --git a/py/selenium/webdriver/common/bidi/script.py b/py/selenium/webdriver/common/bidi/script.py index 6819a5cf63436..1dc8d101d670e 100644 --- a/py/selenium/webdriver/common/bidi/script.py +++ b/py/selenium/webdriver/common/bidi/script.py @@ -15,8 +15,8 @@ # specific language governing permissions and limitations # under the License. -import typing from dataclasses import dataclass +from typing import List from .session import session_subscribe from .session import session_unsubscribe @@ -76,7 +76,7 @@ class ConsoleLogEntry: text: str timestamp: str method: str - args: typing.List[dict] + args: List[dict] type_: str @classmethod diff --git a/py/selenium/webdriver/common/options.py b/py/selenium/webdriver/common/options.py index b31fcc348ce18..9d838a09c0fc2 100644 --- a/py/selenium/webdriver/common/options.py +++ b/py/selenium/webdriver/common/options.py @@ -14,11 +14,12 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing + import warnings from abc import ABCMeta from abc import abstractmethod from enum import Enum +from typing import Optional from selenium.common.exceptions import InvalidArgumentException from selenium.webdriver.common.proxy import Proxy @@ -457,9 +458,9 @@ def set_capability(self, name, value) -> None: def enable_mobile( self, - android_package: typing.Optional[str] = None, - android_activity: typing.Optional[str] = None, - device_serial: typing.Optional[str] = None, + android_package: Optional[str] = None, + android_activity: Optional[str] = None, + device_serial: Optional[str] = None, ) -> None: """Enables mobile browser use for browsers that support it. diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 3afbced1a3e88..7d64d1826bcd6 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -18,14 +18,18 @@ import logging import os import subprocess -import typing from abc import ABC from abc import abstractmethod from io import IOBase from platform import system from subprocess import PIPE from time import sleep +from typing import IO +from typing import Any +from typing import List +from typing import Mapping from typing import Optional +from typing import Union from typing import cast from urllib import request from urllib.error import URLError @@ -53,16 +57,16 @@ def __init__( executable_path: str = None, port: int = 0, log_output: SubprocessStdAlias = None, - env: typing.Optional[typing.Mapping[typing.Any, typing.Any]] = None, + env: Optional[Mapping[Any, Any]] = None, driver_path_env_key: str = None, **kwargs, ) -> None: 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(typing.Optional[typing.Union[int, IOBase]], None) + self.log_output = cast(Optional[Union[int, IOBase]], None) elif log_output is None or log_output == subprocess.DEVNULL: - self.log_output = cast(typing.Optional[typing.Union[int, IOBase]], subprocess.DEVNULL) + self.log_output = cast(Optional[Union[int, IOBase]], subprocess.DEVNULL) else: self.log_output = log_output @@ -80,7 +84,7 @@ def service_url(self) -> str: return f"http://{utils.join_host_port('localhost', self.port)}" @abstractmethod - def command_line_args(self) -> typing.List[str]: + def command_line_args(self) -> List[str]: """A List of program arguments (excluding the executable).""" raise NotImplementedError("This method needs to be implemented in a sub class") @@ -215,8 +219,8 @@ def _start_process(self, path: str) -> None: cmd, env=self.env, close_fds=close_file_descriptors, - stdout=cast(typing.Optional[typing.Union[int, typing.IO[typing.Any]]], self.log_output), - stderr=cast(typing.Optional[typing.Union[int, typing.IO[typing.Any]]], self.log_output), + stdout=cast(Optional[Union[int, IO[Any]]], self.log_output), + stderr=cast(Optional[Union[int, IO[Any]]], self.log_output), stdin=PIPE, creationflags=self.creation_flags, startupinfo=start_info, diff --git a/py/selenium/webdriver/common/virtual_authenticator.py b/py/selenium/webdriver/common/virtual_authenticator.py index cfc467307f923..6e1deb684c898 100644 --- a/py/selenium/webdriver/common/virtual_authenticator.py +++ b/py/selenium/webdriver/common/virtual_authenticator.py @@ -16,10 +16,13 @@ # under the License. import functools -import typing from base64 import urlsafe_b64decode from base64 import urlsafe_b64encode from enum import Enum +from typing import Any +from typing import Dict +from typing import Optional +from typing import Union class Protocol(str, Enum): @@ -65,7 +68,7 @@ def __init__( self.is_user_consenting: bool = is_user_consenting self.is_user_verified: bool = is_user_verified - def to_dict(self) -> typing.Dict[str, typing.Union[str, bool]]: + def to_dict(self) -> Dict[str, Union[str, bool]]: return { "protocol": self.protocol, "transport": self.transport, @@ -82,7 +85,7 @@ def __init__( credential_id: bytes, is_resident_credential: bool, rp_id: str, - user_handle: typing.Optional[bytes], + user_handle: Optional[bytes], private_key: bytes, sign_count: int, ): @@ -117,7 +120,7 @@ def rp_id(self) -> str: return self._rp_id @property - def user_handle(self) -> typing.Optional[str]: + def user_handle(self) -> Optional[str]: if self._user_handle: return urlsafe_b64encode(self._user_handle).decode() return None @@ -147,7 +150,7 @@ def create_non_resident_credential(cls, id: bytes, rp_id: str, private_key: byte @classmethod def create_resident_credential( - cls, id: bytes, rp_id: str, user_handle: typing.Optional[bytes], private_key: bytes, sign_count: int + cls, id: bytes, rp_id: str, user_handle: Optional[bytes], private_key: bytes, sign_count: int ) -> "Credential": """Creates a resident (i.e. stateful) credential. @@ -163,7 +166,7 @@ def create_resident_credential( """ return cls(id, True, rp_id, user_handle, private_key, sign_count) - def to_dict(self) -> typing.Dict[str, typing.Any]: + def to_dict(self) -> Dict[str, Any]: credential_data = { "credentialId": self.id, "isResidentCredential": self._is_resident_credential, @@ -178,7 +181,7 @@ def to_dict(self) -> typing.Dict[str, typing.Any]: return credential_data @classmethod - def from_dict(cls, data: typing.Dict[str, typing.Any]) -> "Credential": + def from_dict(cls, data: Dict[str, Any]) -> "Credential": _id = urlsafe_b64decode(f"{data['credentialId']}==") is_resident_credential = bool(data["isResidentCredential"]) rp_id = data.get("rpId", None) diff --git a/py/selenium/webdriver/edge/service.py b/py/selenium/webdriver/edge/service.py index b2c7f02faf4f7..ea49d8c5ca3a0 100644 --- a/py/selenium/webdriver/edge/service.py +++ b/py/selenium/webdriver/edge/service.py @@ -14,7 +14,10 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing + +from typing import List +from typing import Mapping +from typing import Optional from selenium.types import SubprocessStdAlias from selenium.webdriver.chromium import service @@ -36,8 +39,8 @@ def __init__( executable_path: str = None, port: int = 0, log_output: SubprocessStdAlias = None, - service_args: typing.Optional[typing.List[str]] = None, - env: typing.Optional[typing.Mapping[str, str]] = None, + service_args: Optional[List[str]] = None, + env: Optional[Mapping[str, str]] = None, driver_path_env_key: str = None, **kwargs, ) -> None: diff --git a/py/selenium/webdriver/firefox/service.py b/py/selenium/webdriver/firefox/service.py index e34431480547e..59c8c18058b3b 100644 --- a/py/selenium/webdriver/firefox/service.py +++ b/py/selenium/webdriver/firefox/service.py @@ -14,8 +14,9 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing from typing import List +from typing import Mapping +from typing import Optional from selenium.types import SubprocessStdAlias from selenium.webdriver.common import service @@ -37,9 +38,9 @@ def __init__( self, executable_path: str = None, port: int = 0, - service_args: typing.Optional[typing.List[str]] = None, + service_args: Optional[List[str]] = None, log_output: SubprocessStdAlias = None, - env: typing.Optional[typing.Mapping[str, str]] = None, + env: Optional[Mapping[str, str]] = None, driver_path_env_key: str = None, **kwargs, ) -> None: diff --git a/py/selenium/webdriver/ie/service.py b/py/selenium/webdriver/ie/service.py index b8fac381d9f35..bd9c116ced459 100644 --- a/py/selenium/webdriver/ie/service.py +++ b/py/selenium/webdriver/ie/service.py @@ -14,8 +14,8 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing from typing import List +from typing import Optional from selenium.types import SubprocessStdAlias from selenium.webdriver.common import service @@ -28,9 +28,9 @@ def __init__( self, executable_path: str = None, port: int = 0, - host: typing.Optional[str] = None, - service_args: typing.Optional[typing.List[str]] = None, - log_level: typing.Optional[str] = None, + host: Optional[str] = None, + service_args: Optional[List[str]] = None, + log_level: Optional[str] = None, log_output: SubprocessStdAlias = None, driver_path_env_key: str = None, **kwargs, diff --git a/py/selenium/webdriver/remote/webdriver.py b/py/selenium/webdriver/remote/webdriver.py index eace710c20310..27e6114e06d99 100644 --- a/py/selenium/webdriver/remote/webdriver.py +++ b/py/selenium/webdriver/remote/webdriver.py @@ -22,7 +22,6 @@ import pkgutil import tempfile import types -import typing import warnings import zipfile from abc import ABCMeta @@ -34,6 +33,7 @@ from typing import Dict from typing import List from typing import Optional +from typing import Type from typing import Union from selenium.common.exceptions import InvalidArgumentException @@ -252,9 +252,9 @@ def __enter__(self): def __exit__( self, - exc_type: typing.Optional[typing.Type[BaseException]], - exc: typing.Optional[BaseException], - traceback: typing.Optional[types.TracebackType], + exc_type: Optional[Type[BaseException]], + exc: Optional[BaseException], + traceback: Optional[types.TracebackType], ): self.quit() @@ -618,7 +618,7 @@ def get_cookies(self) -> List[dict]: """ return self.execute(Command.GET_ALL_COOKIES)["value"] - def get_cookie(self, name) -> typing.Optional[typing.Dict]: + def get_cookie(self, name) -> Optional[Dict]: """Get a single cookie by name. Returns the cookie if found, None if not. diff --git a/py/selenium/webdriver/safari/options.py b/py/selenium/webdriver/safari/options.py index 4e7ef0b63b01d..74b39609d6cda 100644 --- a/py/selenium/webdriver/safari/options.py +++ b/py/selenium/webdriver/safari/options.py @@ -14,7 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing +from typing import Dict from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.options import ArgOptions @@ -111,5 +111,5 @@ class Options(ArgOptions): """ @property - def default_capabilities(self) -> typing.Dict[str, str]: + def default_capabilities(self) -> Dict[str, str]: return DesiredCapabilities.SAFARI.copy() diff --git a/py/selenium/webdriver/safari/service.py b/py/selenium/webdriver/safari/service.py index bd04ab66ff483..c20e2ec85df05 100644 --- a/py/selenium/webdriver/safari/service.py +++ b/py/selenium/webdriver/safari/service.py @@ -15,7 +15,10 @@ # specific language governing permissions and limitations # under the License. -import typing + +from typing import List +from typing import Mapping +from typing import Optional from selenium.webdriver.common import service @@ -35,8 +38,8 @@ def __init__( self, executable_path: str = None, port: int = 0, - service_args: typing.Optional[typing.List[str]] = None, - env: typing.Optional[typing.Mapping[str, str]] = None, + service_args: Optional[List[str]] = None, + env: Optional[Mapping[str, str]] = None, reuse_service=False, enable_logging: bool = False, driver_path_env_key: str = None, @@ -57,7 +60,7 @@ def __init__( **kwargs, ) - def command_line_args(self) -> typing.List[str]: + def command_line_args(self) -> List[str]: return ["-p", f"{self.port}"] + self.service_args @property diff --git a/py/selenium/webdriver/support/event_firing_webdriver.py b/py/selenium/webdriver/support/event_firing_webdriver.py index 544ffbb970b6e..6cfdf7b9fb93b 100644 --- a/py/selenium/webdriver/support/event_firing_webdriver.py +++ b/py/selenium/webdriver/support/event_firing_webdriver.py @@ -14,7 +14,10 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing + +from typing import Any +from typing import List +from typing import Tuple from selenium.common.exceptions import WebDriverException from selenium.webdriver.common.by import By @@ -103,12 +106,10 @@ def quit(self) -> None: def find_element(self, by=By.ID, value=None) -> WebElement: return self._dispatch("find", (by, value, self._driver), "find_element", (by, value)) - def find_elements(self, by=By.ID, value=None) -> typing.List[WebElement]: + def find_elements(self, by=By.ID, value=None) -> List[WebElement]: return self._dispatch("find", (by, value, self._driver), "find_elements", (by, value)) - def _dispatch( - self, l_call: str, l_args: typing.Tuple[typing.Any, ...], d_call: str, d_args: typing.Tuple[typing.Any, ...] - ): + def _dispatch(self, l_call: str, l_args: Tuple[Any, ...], d_call: str, d_args: Tuple[Any, ...]): getattr(self._listener, f"before_{l_call}")(*l_args) try: result = getattr(self._driver, d_call)(*d_args) @@ -187,7 +188,7 @@ def send_keys(self, *value) -> None: def find_element(self, by=By.ID, value=None) -> WebElement: return self._dispatch("find", (by, value, self._driver), "find_element", (by, value)) - def find_elements(self, by=By.ID, value=None) -> typing.List[WebElement]: + def find_elements(self, by=By.ID, value=None) -> List[WebElement]: return self._dispatch("find", (by, value, self._driver), "find_elements", (by, value)) def _dispatch(self, l_call, l_args, d_call, d_args): diff --git a/py/selenium/webdriver/support/wait.py b/py/selenium/webdriver/support/wait.py index 35bd74a695eb8..f9e3815b6022f 100644 --- a/py/selenium/webdriver/support/wait.py +++ b/py/selenium/webdriver/support/wait.py @@ -16,10 +16,12 @@ # under the License. import time -import typing from typing import Callable from typing import Generic from typing import Literal +from typing import Optional +from typing import Tuple +from typing import Type from typing import TypeVar from typing import Union @@ -30,7 +32,7 @@ from selenium.webdriver.remote.webelement import WebElement POLL_FREQUENCY: float = 0.5 # How long to sleep in between calls to the method -IGNORED_EXCEPTIONS: typing.Tuple[typing.Type[Exception]] = (NoSuchElementException,) # default to be ignored. +IGNORED_EXCEPTIONS: Tuple[Type[Exception]] = (NoSuchElementException,) # default to be ignored. D = TypeVar("D", bound=Union[WebDriver, WebElement]) T = TypeVar("T") @@ -42,7 +44,7 @@ def __init__( driver: D, timeout: float, poll_frequency: float = POLL_FREQUENCY, - ignored_exceptions: typing.Optional[WaitExcTypes] = None, + ignored_exceptions: Optional[WaitExcTypes] = None, ): """Constructor, takes a WebDriver instance and timeout in seconds. diff --git a/py/selenium/webdriver/webkitgtk/service.py b/py/selenium/webdriver/webkitgtk/service.py index 5f42d31486143..7414556370bd0 100644 --- a/py/selenium/webdriver/webkitgtk/service.py +++ b/py/selenium/webdriver/webkitgtk/service.py @@ -14,8 +14,10 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing import warnings +from typing import List +from typing import Mapping +from typing import Optional from selenium.webdriver.common import service @@ -37,10 +39,10 @@ def __init__( self, executable_path: str = DEFAULT_EXECUTABLE_PATH, port: int = 0, - log_path: typing.Optional[str] = None, - log_output: typing.Optional[str] = None, - service_args: typing.Optional[typing.List[str]] = None, - env: typing.Optional[typing.Mapping[str, str]] = None, + log_path: Optional[str] = None, + log_output: Optional[str] = None, + service_args: Optional[List[str]] = None, + env: Optional[Mapping[str, str]] = None, **kwargs, ) -> None: self.service_args = service_args or [] @@ -56,5 +58,5 @@ def __init__( **kwargs, ) - def command_line_args(self) -> typing.List[str]: + def command_line_args(self) -> List[str]: return ["-p", f"{self.port}"] + self.service_args diff --git a/py/selenium/webdriver/wpewebkit/options.py b/py/selenium/webdriver/wpewebkit/options.py index e1bb66c162a39..5a9736c72d29e 100644 --- a/py/selenium/webdriver/wpewebkit/options.py +++ b/py/selenium/webdriver/wpewebkit/options.py @@ -14,7 +14,8 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing + +from typing import Dict from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.options import ArgOptions @@ -60,5 +61,5 @@ def to_capabilities(self): return caps @property - def default_capabilities(self) -> typing.Dict[str, str]: + def default_capabilities(self) -> Dict[str, str]: return DesiredCapabilities.WPEWEBKIT.copy() diff --git a/py/selenium/webdriver/wpewebkit/service.py b/py/selenium/webdriver/wpewebkit/service.py index bd90f51daf61b..8f392cf522706 100644 --- a/py/selenium/webdriver/wpewebkit/service.py +++ b/py/selenium/webdriver/wpewebkit/service.py @@ -15,7 +15,9 @@ # specific language governing permissions and limitations # under the License. import shutil -import typing +from typing import List +from typing import Mapping +from typing import Optional from selenium.webdriver.common import service @@ -37,9 +39,9 @@ def __init__( self, executable_path: str = DEFAULT_EXECUTABLE_PATH, port: int = 0, - log_output: typing.Optional[str] = None, - service_args: typing.Optional[typing.List[str]] = None, - env: typing.Optional[typing.Mapping[str, str]] = None, + log_output: Optional[str] = None, + service_args: Optional[List[str]] = None, + env: Optional[Mapping[str, str]] = None, **kwargs, ): self.service_args = service_args or [] @@ -51,5 +53,5 @@ def __init__( **kwargs, ) - def command_line_args(self) -> typing.List[str]: + def command_line_args(self) -> List[str]: return ["-p", f"{self.port}"] + self.service_args