lint: Accept ruff suggestions for cast()

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
This commit is contained in:
Jussi Kukkonen 2025-03-18 18:20:11 +02:00
parent 075949fece
commit f3eddc19ff
4 changed files with 8 additions and 8 deletions

View file

@ -81,7 +81,7 @@ def from_bytes(cls, data: bytes) -> SimpleEnvelope[T]:
except Exception as e:
raise DeserializationError from e
return cast(SimpleEnvelope[T], envelope)
return cast("SimpleEnvelope[T]", envelope)
def to_bytes(self) -> bytes:
"""Return envelope as JSON bytes.
@ -150,4 +150,4 @@ def get_signed(self) -> T:
except Exception as e:
raise DeserializationError from e
return cast(T, inner_cls.from_dict(payload_dict))
return cast("T", inner_cls.from_dict(payload_dict))

View file

@ -199,7 +199,7 @@ def from_dict(cls, metadata: dict[str, Any]) -> Metadata[T]:
return cls(
# Specific type T is not known at static type check time: use cast
signed=cast(T, inner_cls.from_dict(metadata.pop("signed"))),
signed=cast("T", inner_cls.from_dict(metadata.pop("signed"))),
signatures=signatures,
# All fields left in the metadata dict are unrecognized.
unrecognized_fields=metadata,

View file

@ -145,22 +145,22 @@ def __iter__(self) -> Iterator[Signed]:
@property
def root(self) -> Root:
"""Get current root."""
return cast(Root, self._trusted_set[Root.type])
return cast("Root", self._trusted_set[Root.type])
@property
def timestamp(self) -> Timestamp:
"""Get current timestamp."""
return cast(Timestamp, self._trusted_set[Timestamp.type])
return cast("Timestamp", self._trusted_set[Timestamp.type])
@property
def snapshot(self) -> Snapshot:
"""Get current snapshot."""
return cast(Snapshot, self._trusted_set[Snapshot.type])
return cast("Snapshot", self._trusted_set[Snapshot.type])
@property
def targets(self) -> Targets:
"""Get current top-level targets."""
return cast(Targets, self._trusted_set[Targets.type])
return cast("Targets", self._trusted_set[Targets.type])
# Methods for updating metadata
def update_root(self, data: bytes) -> Root:

View file

@ -459,7 +459,7 @@ def _load_targets(self, role: str, parent_role: str) -> Targets:
# Avoid loading 'role' more than once during "get_targetinfo"
if role in self._trusted_set:
return cast(Targets, self._trusted_set[role])
return cast("Targets", self._trusted_set[role])
try:
data = self._load_local_metadata(role)