Skip to content

Commit d51896e

Browse files
committed
update retry classes: remove slots & move __eq__ to concrete classes
1 parent dcd3404 commit d51896e

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

redis/asyncio/retry.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ class Retry(AbstractRetry):
1212
ConnectionError,
1313
TimeoutError,
1414
)
15+
__hash__ = AbstractRetry.__hash__
16+
17+
def __eq__(self, other: Any) -> bool:
18+
if not isinstance(other, Retry):
19+
return NotImplemented
20+
21+
return (
22+
self._backoff == other._backoff
23+
and self._retries == other._retries
24+
and set(self._supported_errors) == set(other._supported_errors)
25+
)
1526

1627
async def call_with_retry(
1728
self, do: Callable[[], Awaitable[T]], fail: Callable[[Exception], Any]

redis/retry.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import abc
12
import socket
23
from time import sleep
34
from typing import TYPE_CHECKING, Any, Callable, Iterable, Tuple, Type, TypeVar, Union
@@ -10,10 +11,9 @@
1011
from redis.backoff import AbstractBackoff
1112

1213

13-
class AbstractRetry:
14+
class AbstractRetry(abc.ABC):
1415
"""Retry a specific number of times after a failure"""
1516

16-
__slots__ = "_backoff", "_retries", "_supported_errors"
1717
_supported_errors: Tuple[Type[Exception], ...]
1818

1919
def __init__(
@@ -34,15 +34,9 @@ def __init__(
3434
if supported_errors:
3535
self._supported_errors = supported_errors
3636

37+
@abc.abstractmethod
3738
def __eq__(self, other: Any) -> bool:
38-
if not isinstance(other, AbstractRetry):
39-
return NotImplemented
40-
41-
return (
42-
self._backoff == other._backoff
43-
and self._retries == other._retries
44-
and set(self._supported_errors) == set(other._supported_errors)
45-
)
39+
return NotImplemented
4640

4741
def __hash__(self) -> int:
4842
return hash((self._backoff, self._retries, frozenset(self._supported_errors)))
@@ -76,6 +70,17 @@ class Retry(AbstractRetry):
7670
TimeoutError,
7771
socket.timeout,
7872
)
73+
__hash__ = AbstractRetry.__hash__
74+
75+
def __eq__(self, other: Any) -> bool:
76+
if not isinstance(other, Retry):
77+
return NotImplemented
78+
79+
return (
80+
self._backoff == other._backoff
81+
and self._retries == other._retries
82+
and set(self._supported_errors) == set(other._supported_errors)
83+
)
7984

8085
def call_with_retry(
8186
self,

0 commit comments

Comments
 (0)