Skip to content

[py] Fix: Mypy type annotation errors #15841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 2, 2025
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
23 changes: 15 additions & 8 deletions py/selenium/webdriver/common/bidi/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional, Union
from typing import Any, Optional, Union

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

Expand Down Expand Up @@ -85,12 +85,19 @@ def from_dict(cls, data: dict) -> "Cookie":
-------
Cookie: A new instance of Cookie.
"""
value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value"))
# 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=data.get("name"),
name=str(name),
value=value,
domain=data.get("domain"),
domain=str(domain),
path=data.get("path"),
size=data.get("size"),
http_only=data.get("httpOnly"),
Expand Down Expand Up @@ -125,14 +132,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:
Expand Down Expand Up @@ -242,14 +249,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,
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: Optional[dict[str, str]] = None
self._ignore_local_proxy = False

@property
Expand Down
12 changes: 6 additions & 6 deletions py/selenium/webdriver/common/virtual_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down