style(client.py): correct property typing

This commit is contained in:
2026-03-03 17:46:06 +01:00
parent faecc38261
commit 62acc4b181

View File

@@ -14,7 +14,10 @@ class Client:
"""Represents a client.""" """Represents a client."""
def __init__( def __init__(
self, id: str | None, addr: tuple[str, int], socket: socket.socket self,
id: str | None,
addr: tuple[str, int] | None,
socket: socket.socket | None,
) -> None: ) -> None:
"""Initialize the client. """Initialize the client.
@@ -33,13 +36,15 @@ class Client:
self.last_seen: float = 0.0 # unix timestanp of last inbound message self.last_seen: float = 0.0 # unix timestanp of last inbound message
self.status: ClientStatus = ClientStatus.PENDING self.status: ClientStatus = ClientStatus.PENDING
self.socket: socket.socket = socket self.socket: socket.socket | None = socket
self.addr: tuple[str, int] = addr self.addr: tuple[str, int] | None = addr
self.inbound: bytes = b"" self.inbound: bytes = b""
self.outbound: bytes = b"" self.outbound: bytes = b""
def __str__(self) -> str: def __str__(self) -> str:
return f"Client({self.id} ({self.addr[0]}:{self.addr[1]}))" if self.addr:
return f"Client({self.id} ({self.addr[0]}:{self.addr[1]}))"
return f"Client({self.id} (not connected))"
def __repr__(self) -> str: def __repr__(self) -> str:
return f"Client({self.id}, {self.addr})" return f"Client({self.id}, {self.addr})"
@@ -47,6 +52,11 @@ class Client:
def disconnect(self) -> None: def disconnect(self) -> None:
"""Disconnect the client and close the socket.""" """Disconnect the client and close the socket."""
self.logger.debug(f"Disconnecting Client {self}...") self.logger.debug(f"Disconnecting Client {self}...")
if self.socket is None:
self.logger.warning(
f"Client {self} not connected, nothing to disconnect."
)
return
try: try:
self.socket.close() self.socket.close()
except Exception as e: except Exception as e: