Skip to content
27 changes: 18 additions & 9 deletions common/devtools/pdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# found in the LICENSE file.

from __future__ import print_function
import collections
from collections import OrderedDict
import json
import re
import sys
from typing import Any

description = ""

Expand All @@ -23,10 +24,12 @@
]


def assignType(item, type, is_array=False, map_binary_to_string=False):
def assignType(
item: dict, type: str, is_array: bool = False, map_binary_to_string: bool = False
) -> None:
if is_array:
item["type"] = "array"
item["items"] = collections.OrderedDict()
item["items"] = OrderedDict()
assignType(item["items"], type, False, map_binary_to_string)
return

Expand All @@ -40,8 +43,10 @@ def assignType(item, type, is_array=False, map_binary_to_string=False):
item["$ref"] = type


def createItem(d, experimental, deprecated, name=None):
result = collections.OrderedDict(d)
def createItem(
d: dict, experimental: bool | Any, deprecated: bool | Any, name: str | Any = None
) -> OrderedDict[str, Any]:
result = OrderedDict(d)
if name:
result["name"] = name
global description
Expand All @@ -54,9 +59,11 @@ def createItem(d, experimental, deprecated, name=None):
return result


def parse(data, file_name, map_binary_to_string=False):
protocol = collections.OrderedDict()
protocol["version"] = collections.OrderedDict()
def parse(
data: str, file_name: str, map_binary_to_string: bool = False
) -> OrderedDict[str, Any]:
protocol = OrderedDict()
protocol["version"] = OrderedDict()
protocol["domains"] = []
domain = None
item = None
Expand Down Expand Up @@ -183,7 +190,9 @@ def parse(data, file_name, map_binary_to_string=False):
return protocol


def loads(data, file_name, map_binary_to_string=False):
def loads(
data: str, file_name: str, map_binary_to_string: bool = False
) -> OrderedDict[str, Any] | Any:
if file_name.endswith(".pdl"):
return parse(data, file_name, map_binary_to_string)
return json.loads(data)
5 changes: 5 additions & 0 deletions py/selenium/webdriver/chromium/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def __init__(
self.service.path = self.service.env_path() or finder.get_driver_path()
self.service.start()

if browser_name is None:
raise ValueError("browser_name must be specified")
if vendor_prefix is None:
raise ValueError("vendor_prefix must be specified")

executor = ChromiumRemoteConnection(
remote_server_addr=self.service.service_url,
browser_name=browser_name,
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/common/virtual_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def is_resident_credential(self) -> bool:
return self._is_resident_credential

@property
def rp_id(self) -> str:
def rp_id(self) -> Optional[str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will _rp_id ever not be a string? If it might be None, we should define the return as: str | None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_rp_id can be None if rp_id is not in the dictionary and is assigned the default value None.

rp_id = data.get("rpId", None)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it might be None, we should define the return as: str | None

why not Optional[str] , isn't it equal to str | None ?

return self._rp_id

@property
Expand Down
24 changes: 12 additions & 12 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,18 @@ def __init__(
self.start_session(capabilities)
self._fedcm = FedCM(self)

self._websocket_connection = None
self._script = None
self._network = None
self._browser = None
self._bidi_session = None
self._browsing_context = None
self._storage = None
self._webextension = None
self._permissions = None
self._emulation = None
self._input = None
self._devtools = None
self._websocket_connection: Optional[WebSocketConnection] = None
self._script: Optional[Script] = None
self._network: Optional[Network] = None
self._browser: Optional[Browser] = None
self._bidi_session: Optional[Session] = None
self._browsing_context: Optional[BrowsingContext] = None
self._storage: Optional[Storage] = None
self._webextension: Optional[WebExtension] = None
self._permissions: Optional[Permissions] = None
self._emulation: Optional[Emulation] = None
self._input: Optional[Input] = None
self._devtools: Optional[Any] = None

def __repr__(self) -> str:
return f'<{type(self).__module__}.{type(self).__name__} (session="{self.session_id}")>'
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/safari/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class Options(ArgOptions):
SAFARI_TECH_PREVIEW = "Safari Technology Preview"

# creating descriptor objects
automatic_inspection: bool = _SafariOptionsDescriptor(AUTOMATIC_INSPECTION, bool)
automatic_inspection = _SafariOptionsDescriptor(AUTOMATIC_INSPECTION, bool)
"""Whether to enable automatic inspection."""

automatic_profiling: bool = _SafariOptionsDescriptor(AUTOMATIC_PROFILING, bool)
automatic_profiling = _SafariOptionsDescriptor(AUTOMATIC_PROFILING, bool)
"""Whether to enable automatic profiling."""

use_technology_preview: bool = _SafariOptionsDescriptor(SAFARI_TECH_PREVIEW, bool)
use_technology_preview = _SafariOptionsDescriptor(SAFARI_TECH_PREVIEW, bool)
"""Whether to use Safari Technology Preview."""

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

from typing import Any

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.options import ArgOptions

Expand Down Expand Up @@ -59,7 +61,7 @@ def to_capabilities(self) -> dict:
"""Create a capabilities dictionary with all set options."""
caps = self._caps

browser_options = {}
browser_options: dict[str, Any] = {}
if self.binary_location:
browser_options["binary"] = self.binary_location
if self.arguments:
Expand Down