Review, unify and simplify retry_range usage

This commit is contained in:
Lonami Exo
2022-01-24 11:29:02 +01:00
parent b0b1f30436
commit a25f019964
2 changed files with 7 additions and 20 deletions

View File

@@ -102,23 +102,11 @@ def strip_text(text, entities):
return text
def retry_range(retries, force_retry=True):
def retry_range(retries):
"""
Generates an integer sequence starting from 1. If `retries` is
not a zero or a positive integer value, the sequence will be
infinite, otherwise it will end at `retries + 1`.
Generates an integer sequence starting from 1, always returning once, and adding the given retries.
"""
# We need at least one iteration even if the retries are 0
# when force_retry is True.
if force_retry and not (retries is None or retries < 0):
retries += 1
attempt = 0
while attempt != retries:
attempt += 1
yield attempt
return range(1, max(retries, 0) + 2)
async def _maybe_await(value):