Skip to content

Commit a20c7f3

Browse files
committed
Use assert to check for None values
This is done only for hinting 'mypy' that we have ensured these values cannot be None. 'Bandit' raises warnings for assert usage in the code but we are disabling them since we do not rely upon 'asserts' for any runtime checks but only for type checking. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
1 parent 3ba9b3c commit a20c7f3

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

tuf/ngclient/_internal/trusted_metadata_set.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ def update_snapshot(self, data: bytes) -> None:
317317
def _check_final_snapshot(self) -> None:
318318
"""Check snapshot expiry and version before targets is updated"""
319319

320+
assert self.snapshot is not None # nosec
321+
assert self.timestamp is not None # nosec
320322
if self.snapshot.signed.is_expired(self.reference_time):
321323
raise exceptions.ExpiredMetadataError("snapshot.json is expired")
322324

tuf/ngclient/updater.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def _load_snapshot(self) -> None:
345345
# Local snapshot does not exist or is invalid: update from remote
346346
logger.debug("Failed to load local snapshot %s", e)
347347

348+
assert self._trusted_set.timestamp is not None # nosec
348349
metainfo = self._trusted_set.timestamp.signed.meta["snapshot.json"]
349350
length = metainfo.length or self.config.snapshot_max_length
350351
version = None
@@ -365,6 +366,7 @@ def _load_targets(self, role: str, parent_role: str) -> None:
365366
# Local 'role' does not exist or is invalid: update from remote
366367
logger.debug("Failed to load local %s: %s", role, e)
367368

369+
assert self._trusted_set.snapshot is not None # nosec
368370
metainfo = self._trusted_set.snapshot.signed.meta[f"{role}.json"]
369371
length = metainfo.length or self.config.targets_max_length
370372
version = None

0 commit comments

Comments
 (0)