1+ import abc
12import socket
23from time import sleep
34from typing import TYPE_CHECKING , Any , Callable , Iterable , Tuple , Type , TypeVar , Union
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