Skip to content

Commit b0bdb76

Browse files
committed
Add missing type hints for retry.py
1 parent b7a85eb commit b0bdb76

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

redis/retry.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import socket
22
from time import sleep
3+
from typing import TYPE_CHECKING, Any, Iterable, TypeVar, Callable
34

45
from redis.exceptions import ConnectionError, TimeoutError
56

7+
T = TypeVar("T")
8+
9+
if TYPE_CHECKING:
10+
from redis.backoff import AbstractBackoff
11+
612

713
class Retry:
814
"""Retry a specific number of times after a failure"""
915

1016
def __init__(
1117
self,
12-
backoff,
13-
retries,
14-
supported_errors=(ConnectionError, TimeoutError, socket.timeout),
18+
backoff: AbstractBackoff,
19+
retries: int,
20+
supported_errors: tuple[type[Exception], ...] = (
21+
ConnectionError,
22+
TimeoutError,
23+
socket.timeout,
24+
),
1525
):
1626
"""
1727
Initialize a `Retry` object with a `Backoff` object
@@ -24,15 +34,21 @@ def __init__(
2434
self._retries = retries
2535
self._supported_errors = supported_errors
2636

27-
def update_supported_errors(self, specified_errors: list):
37+
def update_supported_errors(
38+
self, specified_errors: Iterable[type[Exception]]
39+
) -> None:
2840
"""
2941
Updates the supported errors with the specified error types
3042
"""
3143
self._supported_errors = tuple(
3244
set(self._supported_errors + tuple(specified_errors))
3345
)
3446

35-
def call_with_retry(self, do, fail):
47+
def call_with_retry(
48+
self,
49+
do: Callable[[], T],
50+
fail: Callable[[Exception], Any],
51+
) -> T:
3652
"""
3753
Execute an operation that might fail and returns its result, or
3854
raise the exception that was thrown depending on the `Backoff` object.

0 commit comments

Comments
 (0)