diff --git a/client/src/telethon/_impl/mtsender/reconnection.py b/client/src/telethon/_impl/mtsender/reconnection.py index 363aad6d..20e38777 100644 --- a/client/src/telethon/_impl/mtsender/reconnection.py +++ b/client/src/telethon/_impl/mtsender/reconnection.py @@ -10,16 +10,15 @@ class ReconnectionPolicy(ABC): """ @abstractmethod - def should_retry(self, attempts: int) -> bool | float: + def should_retry(self, attempts: int) -> float | None: """ Determines whether the client should retry the connection attempt. """ - pass class NoReconnect(ReconnectionPolicy): - def should_retry(self, attempts: int) -> bool: - return False + def should_retry(self, attempts: int) -> float | None: + return None class FixedReconnect(ReconnectionPolicy): @@ -29,8 +28,8 @@ class FixedReconnect(ReconnectionPolicy): self.max_attempts = attempts self.delay = delay - def should_retry(self, attempts: int) -> bool | float: + def should_retry(self, attempts: int) -> float | None: if attempts < self.max_attempts: return self.delay - return False + return None diff --git a/client/src/telethon/_impl/mtsender/sender.py b/client/src/telethon/_impl/mtsender/sender.py index f9b8c1f5..bdfa5e96 100644 --- a/client/src/telethon/_impl/mtsender/sender.py +++ b/client/src/telethon/_impl/mtsender/sender.py @@ -310,10 +310,8 @@ class Sender: delay = self._reconnection_policy.should_retry(attempts) - if delay: - if delay is not True: - await asyncio.sleep(delay) - continue + if delay is not None: + await asyncio.sleep(delay) else: self._logger.error( f"auto-reconnect failed {attempts} time(s); giving up"