Skip to content

Commit

Permalink
ngclient/updater: type certainty in download_target()
Browse files Browse the repository at this point in the history
Re-organise download_target()'s assignment of the target base URL to
ensure mypy can confidently determine that the assigned variable will
never be None.

Signed-off-by: Joshua Lock <jlock@vmware.com>
  • Loading branch information
joshuagl committed Jul 12, 2021
1 parent e4109a0 commit 2aaec55
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tuf/ngclient/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ def download_target(
TODO: download-related errors
TODO: file write errors
"""
if target_base_url is None and self._target_base_url is None:
tgt_base_url: str = self._target_base_url or ""
if target_base_url is not None:
tgt_base_url = _ensure_trailing_slash(target_base_url)

if not tgt_base_url:
raise ValueError(
"target_base_url must be set in either download_target() or "
"constructor"
)
if target_base_url is None:
target_base_url = self._target_base_url
else:
target_base_url = _ensure_trailing_slash(target_base_url)

target_filepath: str = targetinfo["filepath"]
target_fileinfo: TargetFile = targetinfo["fileinfo"]
full_url = parse.urljoin(target_base_url, target_filepath)
full_url = parse.urljoin(tgt_base_url, target_filepath)

with download.download_file(
full_url, target_fileinfo.length, self._fetcher
Expand Down

0 comments on commit 2aaec55

Please sign in to comment.