Fix bug in run_with_retries, better types

This commit is contained in:
Ivan Habunek 2024-04-06 15:05:47 +02:00
parent 1d48e64853
commit 38eca67905
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
1 changed files with 6 additions and 3 deletions

View File

@ -3,7 +3,10 @@ Helpers for testing.
"""
import time
from typing import Any, Callable
from typing import Callable, TypeVar
T = TypeVar("T")
class MockResponse:
@ -24,7 +27,7 @@ def retval(val):
return lambda *args, **kwargs: val
def run_with_retries(fn: Callable[..., Any]):
def run_with_retries(fn: Callable[..., T]) -> T:
"""
Run the the given function repeatedly until it finishes without raising an
AssertionError. Sleep a bit between attempts. If the function doesn't
@ -41,4 +44,4 @@ def run_with_retries(fn: Callable[..., Any]):
except AssertionError:
time.sleep(delay)
fn()
return fn()