Fixed two more cases of unguarded "async for"

This commit is contained in:
Alex Grönholm 2025-06-26 18:28:29 +03:00
parent 3aa2ef51be
commit 7b2b429cf1

View File

@ -485,7 +485,9 @@ class Request:
"""
if not hasattr(self, "_content"):
assert isinstance(self.stream, typing.AsyncIterable)
self._content = b"".join([part async for part in self.stream])
async with safe_async_iterate(self.stream) as iterator:
self._content = b"".join([part async for part in iterator])
if not isinstance(self.stream, ByteStream):
# If a streaming request has been read entirely into memory, then
# we can replace the stream with a raw bytes implementation,
@ -976,7 +978,8 @@ class Response:
Read and return the response content.
"""
if not hasattr(self, "_content"):
self._content = b"".join([part async for part in self.aiter_bytes()])
async with safe_async_iterate(self.aiter_bytes()) as iterator:
self._content = b"".join([part async for part in iterator])
return self._content
async def aiter_bytes(self, chunk_size: int | None = None) -> AsyncGenerator[bytes]: