diff --git a/a2s/a2s_async.py b/a2s/a2s_async.py index 29718c3..9037fb4 100644 --- a/a2s/a2s_async.py +++ b/a2s/a2s_async.py @@ -148,6 +148,14 @@ async def request_async_impl( class A2SProtocol(asyncio.DatagramProtocol): + __slots__ = ( + "recv_queue", + "error_event", + "error", + "fragment_buf", + "transport", + ) + def __init__(self): self.recv_queue: asyncio.Queue[bytes] = asyncio.Queue() self.error_event: asyncio.Event = asyncio.Event() @@ -192,6 +200,12 @@ class A2SProtocol(asyncio.DatagramProtocol): class A2SStreamAsync: + __slots__ = ( + "transport", + "protocol", + "timeout", + ) + def __init__(self, transport: asyncio.DatagramTransport, protocol: A2SProtocol, timeout: float) -> None: self.transport = transport self.protocol = protocol diff --git a/a2s/a2s_fragment.py b/a2s/a2s_fragment.py index 8c7497d..de54b96 100644 --- a/a2s/a2s_fragment.py +++ b/a2s/a2s_fragment.py @@ -29,6 +29,16 @@ from a2s.byteio import ByteReader class A2SFragment: + __slots__ = ( + "message_id", + "fragment_count", + "fragment_id", + "mtu", + "decompressed_size", + "crc", + "payload", + ) + def __init__( self, message_id: int, diff --git a/a2s/a2s_sync.py b/a2s/a2s_sync.py index b26ace8..5a93c00 100644 --- a/a2s/a2s_sync.py +++ b/a2s/a2s_sync.py @@ -48,8 +48,6 @@ logger: logging.Logger = logging.getLogger("a2s") T = TypeVar("T", InfoProtocol, RulesProtocol, PlayersProtocol) -__all__ = ("A2SStream",) - @overload def request_sync( @@ -139,6 +137,11 @@ def request_sync_impl( class A2SStream: + __slots__ = ( + "address", + "_socket", + ) + def __init__(self, address: Tuple[str, int], timeout: float) -> None: self.address: Tuple[str, int] = address self._socket: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/a2s/byteio.py b/a2s/byteio.py index 2bbe734..3eaea6e 100644 --- a/a2s/byteio.py +++ b/a2s/byteio.py @@ -32,7 +32,6 @@ from a2s.exceptions import BufferExhaustedError from .defaults import DEFAULT_ENCODING - if TYPE_CHECKING: from typing_extensions import Literal @@ -42,6 +41,12 @@ STRUCT_OPTIONS = Literal[ class ByteReader: + __slots__ = ( + "stream", + "endian", + "encoding", + ) + def __init__(self, stream: io.BytesIO, endian: str = "=", encoding: Optional[str] = None) -> None: self.stream: io.BytesIO = stream self.endian: str = endian @@ -126,6 +131,12 @@ class ByteReader: class ByteWriter: + __slots__ = ( + "stream", + "endian", + "encoding", + ) + def __init__(self, stream: io.BytesIO, endian: str = "=", encoding: Optional[str] = None) -> None: self.stream: io.BytesIO = stream self.endian: str = endian