mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-09-18 18:02:51 +03:00
Refactor type hints for reconnection policy to use Optional for better clarity
This commit is contained in:
parent
9386210005
commit
55d9343d11
|
@ -1,4 +1,5 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class ReconnectionPolicy(ABC):
|
||||
|
@ -10,14 +11,14 @@ class ReconnectionPolicy(ABC):
|
|||
"""
|
||||
|
||||
@abstractmethod
|
||||
def should_retry(self, attempts: int) -> float | None:
|
||||
def should_retry(self, attempts: int) -> Optional[float]:
|
||||
"""
|
||||
Determines whether the client should retry the connection attempt.
|
||||
"""
|
||||
|
||||
|
||||
class NoReconnect(ReconnectionPolicy):
|
||||
def should_retry(self, attempts: int) -> float | None:
|
||||
def should_retry(self, attempts: int) -> Optional[float]:
|
||||
return None
|
||||
|
||||
|
||||
|
@ -28,7 +29,7 @@ class FixedReconnect(ReconnectionPolicy):
|
|||
self.max_attempts = attempts
|
||||
self.delay = delay
|
||||
|
||||
def should_retry(self, attempts: int) -> float | None:
|
||||
def should_retry(self, attempts: int) -> Optional[float]:
|
||||
if attempts < self.max_attempts:
|
||||
return self.delay
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ class Sender:
|
|||
addr: str
|
||||
mtp: Mtp
|
||||
_connector: Connector
|
||||
_reconnection_policy: ReconnectionPolicy | None
|
||||
_reconnection_policy: Optional[ReconnectionPolicy]
|
||||
_logger: logging.Logger
|
||||
_reader: AsyncReader
|
||||
_writer: AsyncWriter
|
||||
|
@ -190,7 +190,7 @@ class Sender:
|
|||
addr: str,
|
||||
*,
|
||||
connector: Connector,
|
||||
reconnection_policy: ReconnectionPolicy | None = None,
|
||||
reconnection_policy: Optional[ReconnectionPolicy] = None,
|
||||
base_logger: logging.Logger,
|
||||
) -> Self:
|
||||
ip, port = addr.split(":")
|
||||
|
@ -570,7 +570,7 @@ async def connect(
|
|||
auth_key: Optional[bytes],
|
||||
base_logger: logging.Logger,
|
||||
connector: Connector,
|
||||
reconnection_policy: ReconnectionPolicy | None = None,
|
||||
reconnection_policy: Optional[ReconnectionPolicy] = None,
|
||||
) -> Sender:
|
||||
if auth_key is None:
|
||||
sender = await Sender.connect(
|
||||
|
|
Loading…
Reference in New Issue
Block a user