Skip to content

Commit dd3c209

Browse files
committed
Update StreamResponse.write annotation for strict-bytes
1 parent 7f8e2d3 commit dd3c209

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

CHANGES/10154.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated ``StreamResponse.write`` annotation to also allow ``bytearray`` and ``memoryview`` as inputs.

aiohttp/abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class AbstractStreamWriter(ABC):
196196
length: Optional[int] = 0
197197

198198
@abstractmethod
199-
async def write(self, chunk: bytes) -> None:
199+
async def write(self, chunk: bytes | bytearray | memoryview) -> None:
200200
"""Write chunk into stream."""
201201

202202
@abstractmethod

aiohttp/http_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def enable_compression(
7272
) -> None:
7373
self._compress = ZLibCompressor(encoding=encoding, strategy=strategy)
7474

75-
def _write(self, chunk: bytes) -> None:
75+
def _write(self, chunk: bytes | bytearray | memoryview) -> None:
7676
size = len(chunk)
7777
self.buffer_size += size
7878
self.output_size += size
@@ -93,7 +93,7 @@ def _writelines(self, chunks: Iterable[bytes]) -> None:
9393
transport.write(b"".join(chunks))
9494

9595
async def write(
96-
self, chunk: bytes, *, drain: bool = True, LIMIT: int = 0x10000
96+
self, chunk: bytes | bytearray | memoryview, *, drain: bool = True, LIMIT: int = 0x10000
9797
) -> None:
9898
"""Writes chunk of data to a stream.
9999

aiohttp/web_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ async def _write_headers(self) -> None:
432432
status_line = f"HTTP/{version[0]}.{version[1]} {self._status} {self._reason}"
433433
await writer.write_headers(status_line, self._headers)
434434

435-
async def write(self, data: bytes) -> None:
435+
async def write(self, data: Union[bytes, bytearray, memoryview]) -> None:
436436
assert isinstance(
437437
data, (bytes, bytearray, memoryview)
438438
), "data argument must be byte-ish (%r)" % type(data)

0 commit comments

Comments
 (0)