1
+ import abc
1
2
import socket
2
3
from time import sleep
3
4
from typing import TYPE_CHECKING , Any , Callable , Iterable , Tuple , Type , TypeVar , Union
10
11
from redis .backoff import AbstractBackoff
11
12
12
13
13
- class AbstractRetry :
14
+ class AbstractRetry ( abc . ABC ) :
14
15
"""Retry a specific number of times after a failure"""
15
16
16
- __slots__ = "_backoff" , "_retries" , "_supported_errors"
17
17
_supported_errors : Tuple [Type [Exception ], ...]
18
18
19
19
def __init__ (
@@ -34,15 +34,9 @@ def __init__(
34
34
if supported_errors :
35
35
self ._supported_errors = supported_errors
36
36
37
+ @abc .abstractmethod
37
38
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
46
40
47
41
def __hash__ (self ) -> int :
48
42
return hash ((self ._backoff , self ._retries , frozenset (self ._supported_errors )))
@@ -76,6 +70,17 @@ class Retry(AbstractRetry):
76
70
TimeoutError ,
77
71
socket .timeout ,
78
72
)
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
+ )
79
84
80
85
def call_with_retry (
81
86
self ,
0 commit comments