mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-09-19 02:12:40 +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 abc import ABC, abstractmethod
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class ReconnectionPolicy(ABC):
|
class ReconnectionPolicy(ABC):
|
||||||
|
@ -10,14 +11,14 @@ class ReconnectionPolicy(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@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.
|
Determines whether the client should retry the connection attempt.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class NoReconnect(ReconnectionPolicy):
|
class NoReconnect(ReconnectionPolicy):
|
||||||
def should_retry(self, attempts: int) -> float | None:
|
def should_retry(self, attempts: int) -> Optional[float]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ class FixedReconnect(ReconnectionPolicy):
|
||||||
self.max_attempts = attempts
|
self.max_attempts = attempts
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
|
|
||||||
def should_retry(self, attempts: int) -> float | None:
|
def should_retry(self, attempts: int) -> Optional[float]:
|
||||||
if attempts < self.max_attempts:
|
if attempts < self.max_attempts:
|
||||||
return self.delay
|
return self.delay
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ class Sender:
|
||||||
addr: str
|
addr: str
|
||||||
mtp: Mtp
|
mtp: Mtp
|
||||||
_connector: Connector
|
_connector: Connector
|
||||||
_reconnection_policy: ReconnectionPolicy | None
|
_reconnection_policy: Optional[ReconnectionPolicy]
|
||||||
_logger: logging.Logger
|
_logger: logging.Logger
|
||||||
_reader: AsyncReader
|
_reader: AsyncReader
|
||||||
_writer: AsyncWriter
|
_writer: AsyncWriter
|
||||||
|
@ -190,7 +190,7 @@ class Sender:
|
||||||
addr: str,
|
addr: str,
|
||||||
*,
|
*,
|
||||||
connector: Connector,
|
connector: Connector,
|
||||||
reconnection_policy: ReconnectionPolicy | None = None,
|
reconnection_policy: Optional[ReconnectionPolicy] = None,
|
||||||
base_logger: logging.Logger,
|
base_logger: logging.Logger,
|
||||||
) -> Self:
|
) -> Self:
|
||||||
ip, port = addr.split(":")
|
ip, port = addr.split(":")
|
||||||
|
@ -570,7 +570,7 @@ async def connect(
|
||||||
auth_key: Optional[bytes],
|
auth_key: Optional[bytes],
|
||||||
base_logger: logging.Logger,
|
base_logger: logging.Logger,
|
||||||
connector: Connector,
|
connector: Connector,
|
||||||
reconnection_policy: ReconnectionPolicy | None = None,
|
reconnection_policy: Optional[ReconnectionPolicy] = None,
|
||||||
) -> Sender:
|
) -> Sender:
|
||||||
if auth_key is None:
|
if auth_key is None:
|
||||||
sender = await Sender.connect(
|
sender = await Sender.connect(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user