Skip to content

Commit 7ff0d5e

Browse files
committed
Fixed two more cases of unguarded "async for"
1 parent c6f09e5 commit 7ff0d5e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

httpx/_models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ async def aread(self) -> bytes:
485485
"""
486486
if not hasattr(self, "_content"):
487487
assert isinstance(self.stream, typing.AsyncIterable)
488-
self._content = b"".join([part async for part in self.stream])
488+
async with safe_async_iterate(self.stream) as iterator:
489+
self._content = b"".join([part async for part in iterator])
490+
489491
if not isinstance(self.stream, ByteStream):
490492
# If a streaming request has been read entirely into memory, then
491493
# we can replace the stream with a raw bytes implementation,
@@ -976,7 +978,8 @@ async def aread(self) -> bytes:
976978
Read and return the response content.
977979
"""
978980
if not hasattr(self, "_content"):
979-
self._content = b"".join([part async for part in self.aiter_bytes()])
981+
async with safe_async_iterate(self.aiter_bytes()) as iterator:
982+
self._content = b"".join([part async for part in iterator])
980983
return self._content
981984

982985
async def aiter_bytes(self, chunk_size: int | None = None) -> AsyncGenerator[bytes]:

0 commit comments

Comments
 (0)