From 6f4e9615d74c7d4935c11a2c9497cf6aae7149f3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 24 Nov 2024 15:58:05 -0800 Subject: [PATCH] Small speed up to `StreamWriter.__init__` (#10038) --- aiohttp/abc.py | 4 ++-- aiohttp/http_writer.py | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/aiohttp/abc.py b/aiohttp/abc.py index bfea03ff12a..feeb3ad65c9 100644 --- a/aiohttp/abc.py +++ b/aiohttp/abc.py @@ -191,8 +191,8 @@ def filter_cookies(self, request_url: URL) -> "BaseCookie[str]": class AbstractStreamWriter(ABC): """Abstract stream writer.""" - buffer_size = 0 - output_size = 0 + buffer_size: int = 0 + output_size: int = 0 length: Optional[int] = 0 @abstractmethod diff --git a/aiohttp/http_writer.py b/aiohttp/http_writer.py index c6c80edc3c4..c66fda3d8d0 100644 --- a/aiohttp/http_writer.py +++ b/aiohttp/http_writer.py @@ -38,6 +38,12 @@ class HttpVersion(NamedTuple): class StreamWriter(AbstractStreamWriter): + + length: Optional[int] = None + chunked: bool = False + _eof: bool = False + _compress: Optional[ZLibCompressor] = None + def __init__( self, protocol: BaseProtocol, @@ -46,17 +52,7 @@ def __init__( on_headers_sent: _T_OnHeadersSent = None, ) -> None: self._protocol = protocol - self.loop = loop - self.length = None - self.chunked = False - self.buffer_size = 0 - self.output_size = 0 - - self._eof = False - self._compress: Optional[ZLibCompressor] = None - self._drain_waiter = None - self._on_chunk_sent: _T_OnChunkSent = on_chunk_sent self._on_headers_sent: _T_OnHeadersSent = on_headers_sent