@@ -692,7 +692,9 @@ def _download_file(
692
692
693
693
resuming = False
694
694
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
+ )
696
698
while attempt <= attempts_allowed :
697
699
attempt += 1
698
700
try :
@@ -745,7 +747,7 @@ def _download_file(
745
747
# Catching RequestException lets us retry on timeout & connection
746
748
# errors (among others) in addition to HTTP status errors.
747
749
except requests .RequestException as exc :
748
- attempts_allowed = _check_if_more_attempts_allowed (
750
+ attempts_allowed_or_not = _check_if_more_attempts_allowed (
749
751
path = path ,
750
752
exc = exc ,
751
753
attempt = attempt ,
@@ -755,6 +757,9 @@ def _download_file(
755
757
if not attempts_allowed :
756
758
yield {"status" : "error" , "message" : str (exc )}
757
759
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
758
763
else :
759
764
lgr .warning ("downloader logic: We should not be here!" )
760
765
@@ -1064,7 +1069,7 @@ def _check_if_more_attempts_allowed(
1064
1069
exc .response .status_code ,
1065
1070
exc ,
1066
1071
)
1067
- return
1072
+ return None
1068
1073
elif retry_after := exc .response .headers .get ("Retry-After" ):
1069
1074
# playing safe
1070
1075
if not str (retry_after ).isdigit ():
@@ -1078,7 +1083,7 @@ def _check_if_more_attempts_allowed(
1078
1083
retry_after ,
1079
1084
exc ,
1080
1085
)
1081
- return
1086
+ return None
1082
1087
sleep_amount = int (retry_after )
1083
1088
lgr .debug (
1084
1089
"%s - download failed due to response %d with "
@@ -1090,10 +1095,10 @@ def _check_if_more_attempts_allowed(
1090
1095
)
1091
1096
else :
1092
1097
lgr .debug ("%s - download failed: %s" , path , exc )
1093
- return
1098
+ return None
1094
1099
elif attempt >= attempts_allowed :
1095
1100
lgr .debug ("%s - download failed after %d attempts: %s" , path , attempt , exc )
1096
- return
1101
+ return None
1097
1102
# if is_access_denied(exc) or attempt >= 2:
1098
1103
# raise
1099
1104
# sleep a little and retry
0 commit comments