Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions py/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# This is a copy of https://github.com/HyperionGray/python-chrome-devtools-protocol/blob/master/generator/generate.py
# The license above is theirs and MUST be preserved.

# flake8: noqa

import builtins
from dataclasses import dataclass
Expand All @@ -36,7 +35,9 @@
from pathlib import Path
import re
from textwrap import dedent, indent as tw_indent
from typing import Optional , cast, List, Union, Iterator
from typing import Optional, cast, List, Union

from collections.abc import Iterator

import inflection # type: ignore

Expand Down Expand Up @@ -206,11 +207,11 @@ def from_json(cls, type):
class CdpProperty:
''' A property belonging to a non-primitive CDP type. '''
name: str
description: Optional[str]
type: Optional[str]
ref: Optional[str]
enum: List[str]
items: Optional[CdpItems]
description: str | None
type: str | None
ref: str | None
enum: list[str]
items: CdpItems | None
optional: bool
experimental: bool
deprecated: bool
Expand Down Expand Up @@ -316,11 +317,11 @@ def generate_from_json(self, dict_):
class CdpType:
''' A top-level CDP type. '''
id: str
description: Optional[str]
description: str | None
type: str
items: Optional[CdpItems]
enum: List[str]
properties: List[CdpProperty]
items: CdpItems | None
enum: list[str]
properties: list[CdpProperty]

@classmethod
def from_json(cls, type_):
Expand Down Expand Up @@ -585,8 +586,8 @@ class CdpCommand:
description: str
experimental: bool
deprecated: bool
parameters: List[CdpParameter]
returns: List[CdpReturn]
parameters: list[CdpParameter]
returns: list[CdpReturn]
domain: str

@property
Expand Down Expand Up @@ -712,10 +713,10 @@ def get_refs(self):
class CdpEvent:
''' A CDP event object. '''
name: str
description: Optional[str]
description: str | None
deprecated: bool
experimental: bool
parameters: List[CdpParameter]
parameters: list[CdpParameter]
domain: str

@property
Expand Down Expand Up @@ -786,12 +787,12 @@ def get_refs(self):
class CdpDomain:
''' A CDP domain contains metadata, types, commands, and events. '''
domain: str
description: Optional[str]
description: str | None
experimental: bool
dependencies: List[str]
types: List[CdpType]
commands: List[CdpCommand]
events: List[CdpEvent]
dependencies: list[str]
types: list[CdpType]
commands: list[CdpCommand]
events: list[CdpEvent]

@property
def module(self) -> str:
Expand Down
30 changes: 15 additions & 15 deletions py/selenium/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""Exceptions that may happen in all the webdriver code."""

from collections.abc import Sequence
from typing import Any, Optional
from typing import Any

SUPPORT_MSG = "For documentation on this error, please visit:"
ERROR_URL = "https://www.selenium.dev/documentation/webdriver/troubleshooting/errors"
Expand All @@ -27,7 +27,7 @@ class WebDriverException(Exception):
"""Base webdriver exception."""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
super().__init__()
self.msg = msg
Expand Down Expand Up @@ -73,7 +73,7 @@ class NoSuchElementException(WebDriverException):
"""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#nosuchelementexception"

Expand Down Expand Up @@ -111,7 +111,7 @@ class StaleElementReferenceException(WebDriverException):
"""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#staleelementreferenceexception"

Expand All @@ -134,10 +134,10 @@ class UnexpectedAlertPresentException(WebDriverException):

def __init__(
self,
msg: Optional[Any] = None,
screen: Optional[str] = None,
stacktrace: Optional[Sequence[str]] = None,
alert_text: Optional[str] = None,
msg: Any | None = None,
screen: str | None = None,
stacktrace: Sequence[str] | None = None,
alert_text: str | None = None,
) -> None:
super().__init__(msg, screen, stacktrace)
self.alert_text = alert_text
Expand All @@ -161,7 +161,7 @@ class ElementNotVisibleException(InvalidElementStateException):
"""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementnotvisibleexception"

Expand All @@ -172,7 +172,7 @@ class ElementNotInteractableException(InvalidElementStateException):
"""Thrown when element interactions will hit another element due to paint order."""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementnotinteractableexception"

Expand Down Expand Up @@ -213,7 +213,7 @@ class InvalidSelectorException(WebDriverException):
"""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#invalidselectorexception"

Expand Down Expand Up @@ -252,7 +252,7 @@ class ElementClickInterceptedException(WebDriverException):
"""Thrown when element click fails because another element obscures it."""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementclickinterceptedexception"

Expand All @@ -271,7 +271,7 @@ class InvalidSessionIdException(WebDriverException):
"""Thrown when the given session id is not in the list of active sessions."""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#invalidsessionidexception"

Expand All @@ -282,7 +282,7 @@ class SessionNotCreatedException(WebDriverException):
"""A new session could not be created."""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#sessionnotcreatedexception"

Expand All @@ -297,7 +297,7 @@ class NoSuchDriverException(WebDriverException):
"""Raised when driver is not specified and cannot be located."""

def __init__(
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Any | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}/driver_location"

Expand Down
7 changes: 3 additions & 4 deletions py/selenium/webdriver/chrome/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver.chromium.options import ChromiumOptions
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
Expand All @@ -28,8 +27,8 @@ def default_capabilities(self) -> dict:

def enable_mobile(
self,
android_package: Optional[str] = "com.android.chrome",
android_activity: Optional[str] = None,
device_serial: Optional[str] = None,
android_package: str | None = "com.android.chrome",
android_activity: str | None = None,
device_serial: str | None = None,
) -> None:
super().enable_mobile(android_package, android_activity, device_serial)
5 changes: 2 additions & 3 deletions py/selenium/webdriver/chrome/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
Expand All @@ -29,8 +28,8 @@ def __init__(
self,
remote_server_addr: str,
keep_alive: bool = True,
ignore_proxy: Optional[bool] = False,
client_config: Optional[ClientConfig] = None,
ignore_proxy: bool | None = False,
client_config: ClientConfig | None = None,
) -> None:
super().__init__(
remote_server_addr=remote_server_addr,
Expand Down
9 changes: 4 additions & 5 deletions py/selenium/webdriver/chrome/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


from collections.abc import Mapping, Sequence
from typing import Optional

from selenium.types import SubprocessStdAlias
from selenium.webdriver.chromium import service
Expand All @@ -41,11 +40,11 @@ class Service(service.ChromiumService):

def __init__(
self,
executable_path: Optional[str] = None,
executable_path: str | None = None,
port: int = 0,
service_args: Optional[Sequence[str]] = None,
log_output: Optional[SubprocessStdAlias] = None,
env: Optional[Mapping[str, str]] = None,
service_args: Sequence[str] | None = None,
log_output: SubprocessStdAlias | None = None,
env: Mapping[str, str] | None = None,
**kwargs,
) -> None:
self._service_args = service_args or []
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/chrome/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
Expand All @@ -28,8 +27,8 @@ class WebDriver(ChromiumDriver):

def __init__(
self,
options: Optional[Options] = None,
service: Optional[Service] = None,
options: Options | None = None,
service: Service | None = None,
keep_alive: bool = True,
) -> None:
"""Creates a new instance of the chrome driver.
Expand Down
10 changes: 5 additions & 5 deletions py/selenium/webdriver/chromium/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import base64
import os
from typing import BinaryIO, Optional, Union
from typing import BinaryIO

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.options import ArgOptions
Expand All @@ -32,8 +32,8 @@ def __init__(self) -> None:
self._binary_location: str = ""
self._extension_files: list[str] = []
self._extensions: list[str] = []
self._experimental_options: dict[str, Union[str, int, dict, list[str]]] = {}
self._debugger_address: Optional[str] = None
self._experimental_options: dict[str, str | int | dict | list[str]] = {}
self._debugger_address: str | None = None
self._enable_webextensions: bool = False

@property
Expand All @@ -53,7 +53,7 @@ def binary_location(self, value: str) -> None:
self._binary_location = value

@property
def debugger_address(self) -> Optional[str]:
def debugger_address(self) -> str | None:
"""Returns the address of the remote devtools instance."""
return self._debugger_address

Expand Down Expand Up @@ -116,7 +116,7 @@ def experimental_options(self) -> dict:
"""Returns a dictionary of experimental options for chromium."""
return self._experimental_options

def add_experimental_option(self, name: str, value: Union[str, int, dict, list[str]]) -> None:
def add_experimental_option(self, name: str, value: str | int | dict | list[str]) -> None:
"""Adds an experimental option which is passed to chromium.

Args:
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/chromium/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Optional

from selenium.webdriver.remote.client_config import ClientConfig
from selenium.webdriver.remote.remote_connection import RemoteConnection
Expand All @@ -27,8 +26,8 @@ def __init__(
vendor_prefix: str,
browser_name: str,
keep_alive: bool = True,
ignore_proxy: Optional[bool] = False,
client_config: Optional[ClientConfig] = None,
ignore_proxy: bool | None = False,
client_config: ClientConfig | None = None,
) -> None:
client_config = client_config or ClientConfig(
remote_server_addr=remote_server_addr, keep_alive=keep_alive, timeout=120
Expand Down
13 changes: 6 additions & 7 deletions py/selenium/webdriver/chromium/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from collections.abc import Mapping, Sequence
from io import IOBase
from typing import Optional

from selenium.types import SubprocessStdAlias
from selenium.webdriver.common import service
Expand All @@ -42,20 +41,20 @@ class ChromiumService(service.Service):

def __init__(
self,
executable_path: Optional[str] = None,
executable_path: str | None = None,
port: int = 0,
service_args: Optional[Sequence[str]] = None,
log_output: Optional[SubprocessStdAlias] = None,
env: Optional[Mapping[str, str]] = None,
driver_path_env_key: Optional[str] = None,
service_args: Sequence[str] | None = None,
log_output: SubprocessStdAlias | None = None,
env: Mapping[str, str] | None = None,
driver_path_env_key: str | None = None,
**kwargs,
) -> None:
self._service_args = list(service_args or [])
driver_path_env_key = driver_path_env_key or "SE_CHROMEDRIVER"

if isinstance(log_output, str):
self._service_args.append(f"--log-path={log_output}")
self.log_output: Optional[IOBase] = None
self.log_output: IOBase | None = None
elif isinstance(log_output, IOBase):
self.log_output = log_output
else:
Expand Down
Loading