Skip to content

Commit

Permalink
Yield error if attempts_allowed is not int
Browse files Browse the repository at this point in the history
For that exception we did get logged:

    ❯ grep Assertion /home/yoh/.local/state/dandi-cli/log/2024.12.16*
    /home/yoh/.local/state/dandi-cli/log/2024.12.16-15.24.12Z-119733.log:AssertionError: attempts_allowed_or_not is None of type <class 'NoneType'>

which makes little sense (besides some thread unsafe handling or None becoming
bool(True))). To overcome and avoid need for assert, just fold that
condition directly into "if" statement.
  • Loading branch information
yarikoptic committed Dec 16, 2024
1 parent fe30c7b commit 2f74075
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,14 +803,9 @@ def _download_file(
attempts_allowed=attempts_allowed,
downloaded_in_attempt=downloaded_in_attempt,
)
if not attempts_allowed:
if not isinstance(attempts_allowed_or_not, int) or not attempts_allowed:

Check warning on line 806 in dandi/download.py

View check run for this annotation

Codecov / codecov/patch

dandi/download.py#L806

Added line #L806 was not covered by tests
yield {"status": "error", "message": str(exc)}
return
# for clear(er) typing, here we get only with int
assert isinstance(attempts_allowed_or_not, int), (
f"attempts_allowed_or_not is {attempts_allowed_or_not!r} "
f"of type {type(attempts_allowed_or_not)}"
)
attempts_allowed = attempts_allowed_or_not
else:
lgr.warning("downloader logic: We should not be here!")
Expand Down

0 comments on commit 2f74075

Please sign in to comment.