Skip to content

Commit 3d47594

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

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

redis/asyncio/retry.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ class Retry(AbstractRetry):
1313
TimeoutError,
1414
)
1515

16+
def __eq__(self, other: Any) -> bool:
17+
if not isinstance(other, Retry):
18+
return NotImplemented
19+
20+
return (
21+
self._backoff == other._backoff
22+
and self._retries == other._retries
23+
and set(self._supported_errors) == set(other._supported_errors)
24+
)
25+
1626
async def call_with_retry(
1727
self, do: Callable[[], Awaitable[T]], fail: Callable[[Exception], Any]
1828
) -> T:

redis/retry.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
class AbstractRetry:
1414
"""Retry a specific number of times after a failure"""
1515

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

1918
def __init__(
@@ -34,16 +33,6 @@ def __init__(
3433
if supported_errors:
3534
self._supported_errors = supported_errors
3635

37-
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-
)
46-
4736
def __hash__(self) -> int:
4837
return hash((self._backoff, self._retries, frozenset(self._supported_errors)))
4938

@@ -77,6 +66,16 @@ class Retry(AbstractRetry):
7766
socket.timeout,
7867
)
7968

69+
def __eq__(self, other: Any) -> bool:
70+
if not isinstance(other, Retry):
71+
return NotImplemented
72+
73+
return (
74+
self._backoff == other._backoff
75+
and self._retries == other._retries
76+
and set(self._supported_errors) == set(other._supported_errors)
77+
)
78+
8079
def call_with_retry(
8180
self,
8281
do: Callable[[], T],

0 commit comments

Comments
 (0)