From 20214d1643e5b7e24b4fc208f60dc8e9eac0b71f Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Sun, 1 Jun 2025 20:37:59 +0530 Subject: [PATCH 1/4] Fix: Mypy type annotation errors in storage.py, options.py, and virtual_authenticator.py --- py/selenium/webdriver/common/bidi/storage.py | 15 +++++++-------- py/selenium/webdriver/common/options.py | 2 +- .../webdriver/common/virtual_authenticator.py | 12 ++++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/py/selenium/webdriver/common/bidi/storage.py b/py/selenium/webdriver/common/bidi/storage.py index 620477aeae6da..b4b5faab59d65 100644 --- a/py/selenium/webdriver/common/bidi/storage.py +++ b/py/selenium/webdriver/common/bidi/storage.py @@ -15,8 +15,7 @@ # specific language governing permissions and limitations # under the License. -from typing import Optional, Union - +from typing import Optional, Union, Any from selenium.webdriver.common.bidi.common import command_builder @@ -88,9 +87,9 @@ def from_dict(cls, data: dict) -> "Cookie": value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) return cls( - name=data.get("name"), + name = str(data.get("name") or ""), value=value, - domain=data.get("domain"), + domain = str(data.get("domain") or ""), path=data.get("path"), size=data.get("size"), http_only=data.get("httpOnly"), @@ -125,14 +124,14 @@ def __init__( self.same_site = same_site self.expiry = expiry - def to_dict(self) -> dict: + def to_dict(self) -> dict[str, Any]: """Converts the CookieFilter to a dictionary. Returns: ------- Dict: A dictionary representation of the CookieFilter. """ - result = {} + result: dict[str, Any] = {} if self.name is not None: result["name"] = self.name if self.value is not None: @@ -242,14 +241,14 @@ def __init__( self.same_site = same_site self.expiry = expiry - def to_dict(self) -> dict: + def to_dict(self) -> dict[str, Any]: """Converts the PartialCookie to a dictionary. Returns: ------- Dict: A dictionary representation of the PartialCookie. """ - result = { + result: dict[str, Any] = { "name": self.name, "value": self.value.to_dict(), "domain": self.domain, diff --git a/py/selenium/webdriver/common/options.py b/py/selenium/webdriver/common/options.py index 67e5765645133..0864d5d1d6c07 100644 --- a/py/selenium/webdriver/common/options.py +++ b/py/selenium/webdriver/common/options.py @@ -422,7 +422,7 @@ def __init__(self) -> None: self._caps = self.default_capabilities self._proxy = None self.set_capability("pageLoadStrategy", PageLoadStrategy.normal) - self.mobile_options = None + self.mobile_options: dict[str, str] = {} self._ignore_local_proxy = False @property diff --git a/py/selenium/webdriver/common/virtual_authenticator.py b/py/selenium/webdriver/common/virtual_authenticator.py index a434de83741df..19b0ec615e7c5 100644 --- a/py/selenium/webdriver/common/virtual_authenticator.py +++ b/py/selenium/webdriver/common/virtual_authenticator.py @@ -24,17 +24,17 @@ class Protocol(str, Enum): """Protocol to communicate with the authenticator.""" - CTAP2: str = "ctap2" - U2F: str = "ctap1/u2f" + CTAP2 = "ctap2" + U2F = "ctap1/u2f" class Transport(str, Enum): """Transport method to communicate with the authenticator.""" - BLE: str = "ble" - USB: str = "usb" - NFC: str = "nfc" - INTERNAL: str = "internal" + BLE = "ble" + USB = "usb" + NFC = "nfc" + INTERNAL = "internal" class VirtualAuthenticatorOptions: From 0a59f7fb2ed94f2c007442ae938532de68f51ea1 Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Sun, 1 Jun 2025 20:54:29 +0530 Subject: [PATCH 2/4] Fix : Spacing --- py/selenium/webdriver/common/bidi/storage.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py/selenium/webdriver/common/bidi/storage.py b/py/selenium/webdriver/common/bidi/storage.py index b4b5faab59d65..ab1a83c6acfab 100644 --- a/py/selenium/webdriver/common/bidi/storage.py +++ b/py/selenium/webdriver/common/bidi/storage.py @@ -87,9 +87,9 @@ def from_dict(cls, data: dict) -> "Cookie": value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) return cls( - name = str(data.get("name") or ""), + name=str(data.get("name") or ""), value=value, - domain = str(data.get("domain") or ""), + domain=str(data.get("domain") or ""), path=data.get("path"), size=data.get("size"), http_only=data.get("httpOnly"), @@ -248,7 +248,7 @@ def to_dict(self) -> dict[str, Any]: ------- Dict: A dictionary representation of the PartialCookie. """ - result: dict[str, Any] = { + result: dict[str, Any] = { "name": self.name, "value": self.value.to_dict(), "domain": self.domain, From 0441402c2dd9580b766be320e4d9956c43df444a Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Sun, 1 Jun 2025 21:03:15 +0530 Subject: [PATCH 3/4] Minor fixes --- py/selenium/webdriver/common/bidi/storage.py | 13 ++++++++++--- py/selenium/webdriver/common/options.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/py/selenium/webdriver/common/bidi/storage.py b/py/selenium/webdriver/common/bidi/storage.py index ab1a83c6acfab..c185a0e0ba53b 100644 --- a/py/selenium/webdriver/common/bidi/storage.py +++ b/py/selenium/webdriver/common/bidi/storage.py @@ -84,12 +84,19 @@ def from_dict(cls, data: dict) -> "Cookie": ------- Cookie: A new instance of Cookie. """ + # Validation for empty strings + name = data.get("name") + if not name: + raise ValueError("name is required and cannot be empty") + domain = data.get("domain") + if not domain: + raise ValueError("domain is required and cannot be empty") + value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) - return cls( - name=str(data.get("name") or ""), + name=str(name), value=value, - domain=str(data.get("domain") or ""), + domain=str(domain), path=data.get("path"), size=data.get("size"), http_only=data.get("httpOnly"), diff --git a/py/selenium/webdriver/common/options.py b/py/selenium/webdriver/common/options.py index 0864d5d1d6c07..fc76c6fd832fc 100644 --- a/py/selenium/webdriver/common/options.py +++ b/py/selenium/webdriver/common/options.py @@ -422,7 +422,7 @@ def __init__(self) -> None: self._caps = self.default_capabilities self._proxy = None self.set_capability("pageLoadStrategy", PageLoadStrategy.normal) - self.mobile_options: dict[str, str] = {} + self.mobile_options: Optional[dict[str, str]] = None self._ignore_local_proxy = False @property From b0c44e93a8bcafa3e3915d1d8b29abdd25e9d508 Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Mon, 2 Jun 2025 12:31:05 +0530 Subject: [PATCH 4/4] Lint fixes --- py/selenium/webdriver/common/bidi/storage.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/py/selenium/webdriver/common/bidi/storage.py b/py/selenium/webdriver/common/bidi/storage.py index c185a0e0ba53b..4404baca7a66a 100644 --- a/py/selenium/webdriver/common/bidi/storage.py +++ b/py/selenium/webdriver/common/bidi/storage.py @@ -15,7 +15,8 @@ # specific language governing permissions and limitations # under the License. -from typing import Optional, Union, Any +from typing import Any, Optional, Union + from selenium.webdriver.common.bidi.common import command_builder @@ -88,10 +89,10 @@ def from_dict(cls, data: dict) -> "Cookie": name = data.get("name") if not name: raise ValueError("name is required and cannot be empty") - domain = data.get("domain") + domain = data.get("domain") if not domain: raise ValueError("domain is required and cannot be empty") - + value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) return cls( name=str(name),