Skip to content

Commit

Permalink
api: Lint metadata.py
Browse files Browse the repository at this point in the history
While working using pylint 2.5.3 (from debian package 2.5.3-2)
I noticed those warnings that were not triggered
by current tox configuration.

This will not harm to support several pylint version.

Change-Id: I7f4d5d56a157cab27f19cfe74cd74baa893c1d93
Signed-off-by: Philippe Coval <[email protected]>
  • Loading branch information
rzr committed Mar 2, 2021
1 parent 8308f85 commit b9d894e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class also that has a 'from_dict' factory method. (Currently this is
# metadata['signatures'], call Signature.from_dict for each item, and
# pass a list of Signature objects to the Metadata constructor intead.
return cls(
signed=inner_cls.from_dict(metadata['signed']),
signatures=metadata['signatures'])
signed=inner_cls.from_dict(metadata['signed']),
signatures=metadata['signatures'])


@classmethod
Expand All @@ -122,7 +122,7 @@ def from_json(cls, metadata_json: str) -> 'Metadata':
def from_json_file(
cls, filename: str,
storage_backend: Optional[StorageBackendInterface] = None
) -> 'Metadata':
) -> 'Metadata':
"""Loads JSON-formatted TUF metadata from file storage.
Arguments:
Expand Down Expand Up @@ -155,10 +155,10 @@ def to_dict(self) -> JsonDict:
def to_json(self, compact: bool = False) -> None:
"""Returns the optionally compacted JSON representation of self. """
return json.dumps(
self.to_dict(),
indent=(None if compact else 1),
separators=((',', ':') if compact else (',', ': ')),
sort_keys=True)
self.to_dict(),
indent=(None if compact else 1),
separators=((',', ':') if compact else (',', ': ')),
sort_keys=True)


def to_json_file(
Expand Down Expand Up @@ -232,16 +232,16 @@ def verify(self, key: JsonDict) -> bool:
"""
signatures_for_keyid = list(filter(
lambda sig: sig['keyid'] == key['keyid'], self.signatures))
lambda sig: sig['keyid'] == key['keyid'], self.signatures))

if not signatures_for_keyid:
raise tuf.exceptions.Error(
f'no signature for key {key["keyid"]}.')
f'no signature for key {key["keyid"]}.')

if len(signatures_for_keyid) > 1:
raise tuf.exceptions.Error(
f'{len(signatures_for_keyid)} signatures for key '
f'{key["keyid"]}, not sure which one to verify.')
f'{len(signatures_for_keyid)} signatures for key '
f'{key["keyid"]}, not sure which one to verify.')

return verify_signature(
key, signatures_for_keyid[0],
Expand Down Expand Up @@ -293,7 +293,7 @@ def from_dict(cls, signed_dict: JsonDict) -> 'Signed':
# what the constructor expects and what we store. The inverse operation
# is implemented in 'to_dict'.
signed_dict['expires'] = tuf.formats.expiry_string_to_datetime(
signed_dict['expires'])
signed_dict['expires'])
# NOTE: We write the converted 'expires' back into 'signed_dict' above
# so that we can pass it to the constructor as '**signed_dict' below,
# along with other fields that belong to Signed subclasses.
Expand Down Expand Up @@ -582,7 +582,7 @@ class Targets(Signed):
def __init__(
self, _type: str, version: int, spec_version: str,
expires: datetime, targets: JsonDict, delegations: JsonDict
) -> None:
) -> None:
super().__init__(_type, version, spec_version, expires)
# TODO: Add class for meta
self.targets = targets
Expand Down

0 comments on commit b9d894e

Please sign in to comment.