Refactor type hints for reconnection policy to use Optional for better clarity

This commit is contained in:
Jahongir Qurbonov 2025-09-15 15:00:20 +05:00
parent 9386210005
commit 55d9343d11
No known key found for this signature in database
GPG Key ID: 256976CED13D5F2D
2 changed files with 7 additions and 6 deletions

View File

@ -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

View File

@ -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(