mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
lint: Accept ruff suggestions for cast()
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
This commit is contained in:
parent
075949fece
commit
f3eddc19ff
4 changed files with 8 additions and 8 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue