Skip to content

Commit 449a0b7

Browse files
authored
[py] Fix type annotation errors (#15841)
Fixes type annotation errors in storage.py, options.py, and virtual_authenticator.py
1 parent f52bb20 commit 449a0b7

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

py/selenium/webdriver/common/bidi/storage.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from typing import Optional, Union
18+
from typing import Any, Optional, Union
1919

2020
from selenium.webdriver.common.bidi.common import command_builder
2121

@@ -85,12 +85,19 @@ def from_dict(cls, data: dict) -> "Cookie":
8585
-------
8686
Cookie: A new instance of Cookie.
8787
"""
88-
value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value"))
88+
# Validation for empty strings
89+
name = data.get("name")
90+
if not name:
91+
raise ValueError("name is required and cannot be empty")
92+
domain = data.get("domain")
93+
if not domain:
94+
raise ValueError("domain is required and cannot be empty")
8995

96+
value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value"))
9097
return cls(
91-
name=data.get("name"),
98+
name=str(name),
9299
value=value,
93-
domain=data.get("domain"),
100+
domain=str(domain),
94101
path=data.get("path"),
95102
size=data.get("size"),
96103
http_only=data.get("httpOnly"),
@@ -125,14 +132,14 @@ def __init__(
125132
self.same_site = same_site
126133
self.expiry = expiry
127134

128-
def to_dict(self) -> dict:
135+
def to_dict(self) -> dict[str, Any]:
129136
"""Converts the CookieFilter to a dictionary.
130137
131138
Returns:
132139
-------
133140
Dict: A dictionary representation of the CookieFilter.
134141
"""
135-
result = {}
142+
result: dict[str, Any] = {}
136143
if self.name is not None:
137144
result["name"] = self.name
138145
if self.value is not None:
@@ -242,14 +249,14 @@ def __init__(
242249
self.same_site = same_site
243250
self.expiry = expiry
244251

245-
def to_dict(self) -> dict:
252+
def to_dict(self) -> dict[str, Any]:
246253
"""Converts the PartialCookie to a dictionary.
247254
248255
Returns:
249256
-------
250257
Dict: A dictionary representation of the PartialCookie.
251258
"""
252-
result = {
259+
result: dict[str, Any] = {
253260
"name": self.name,
254261
"value": self.value.to_dict(),
255262
"domain": self.domain,

py/selenium/webdriver/common/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def __init__(self) -> None:
422422
self._caps = self.default_capabilities
423423
self._proxy = None
424424
self.set_capability("pageLoadStrategy", PageLoadStrategy.normal)
425-
self.mobile_options = None
425+
self.mobile_options: Optional[dict[str, str]] = None
426426
self._ignore_local_proxy = False
427427

428428
@property

py/selenium/webdriver/common/virtual_authenticator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
class Protocol(str, Enum):
2525
"""Protocol to communicate with the authenticator."""
2626

27-
CTAP2: str = "ctap2"
28-
U2F: str = "ctap1/u2f"
27+
CTAP2 = "ctap2"
28+
U2F = "ctap1/u2f"
2929

3030

3131
class Transport(str, Enum):
3232
"""Transport method to communicate with the authenticator."""
3333

34-
BLE: str = "ble"
35-
USB: str = "usb"
36-
NFC: str = "nfc"
37-
INTERNAL: str = "internal"
34+
BLE = "ble"
35+
USB = "usb"
36+
NFC = "nfc"
37+
INTERNAL = "internal"
3838

3939

4040
class VirtualAuthenticatorOptions:

0 commit comments

Comments
 (0)