From 5e4ad95e394305fc29aff21b1470cd94e6e2e237 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:18:39 +0000 Subject: [PATCH] [PR #10038/6f4e9615 backport][3.12] Small speed up to `StreamWriter.__init__` (#10040) Co-authored-by: J. Nick Koston --- 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 868f0e94898..d6f9f782b0f 100644 --- a/aiohttp/abc.py +++ b/aiohttp/abc.py @@ -195,8 +195,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