Skip to content

Commit 7efa0b2

Browse files
committed
RF: making type checking happier)
1 parent 7322117 commit 7efa0b2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

dandi/download.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,9 @@ def _download_file(
692692

693693
resuming = False
694694
attempt = 0
695-
attempts_allowed = 3 # number to do, could be incremented if we downloaded a little
695+
attempts_allowed: int = (
696+
3 # number to do, could be incremented if we downloaded a little
697+
)
696698
while attempt <= attempts_allowed:
697699
attempt += 1
698700
try:
@@ -745,7 +747,7 @@ def _download_file(
745747
# Catching RequestException lets us retry on timeout & connection
746748
# errors (among others) in addition to HTTP status errors.
747749
except requests.RequestException as exc:
748-
attempts_allowed = _check_if_more_attempts_allowed(
750+
attempts_allowed_or_not = _check_if_more_attempts_allowed(
749751
path=path,
750752
exc=exc,
751753
attempt=attempt,
@@ -755,6 +757,9 @@ def _download_file(
755757
if not attempts_allowed:
756758
yield {"status": "error", "message": str(exc)}
757759
return
760+
# for clear(er) typing, here we get only with int
761+
assert isinstance(attempts_allowed_or_not, int)
762+
attempts_allowed = attempts_allowed_or_not
758763
else:
759764
lgr.warning("downloader logic: We should not be here!")
760765

@@ -1064,7 +1069,7 @@ def _check_if_more_attempts_allowed(
10641069
exc.response.status_code,
10651070
exc,
10661071
)
1067-
return
1072+
return None
10681073
elif retry_after := exc.response.headers.get("Retry-After"):
10691074
# playing safe
10701075
if not str(retry_after).isdigit():
@@ -1078,7 +1083,7 @@ def _check_if_more_attempts_allowed(
10781083
retry_after,
10791084
exc,
10801085
)
1081-
return
1086+
return None
10821087
sleep_amount = int(retry_after)
10831088
lgr.debug(
10841089
"%s - download failed due to response %d with "
@@ -1090,10 +1095,10 @@ def _check_if_more_attempts_allowed(
10901095
)
10911096
else:
10921097
lgr.debug("%s - download failed: %s", path, exc)
1093-
return
1098+
return None
10941099
elif attempt >= attempts_allowed:
10951100
lgr.debug("%s - download failed after %d attempts: %s", path, attempt, exc)
1096-
return
1101+
return None
10971102
# if is_access_denied(exc) or attempt >= 2:
10981103
# raise
10991104
# sleep a little and retry

0 commit comments

Comments
 (0)