Skip to content

Commit 60ff030

Browse files
committed
Accept AsyncIterables being passed to Response
Fixes pallets/flask#5322
1 parent 2fc6d4f commit 60ff030

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/quart/wrappers/response.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,24 @@ async def __anext__(self) -> bytes:
102102

103103

104104
class IterableBody(ResponseBody):
105-
def __init__(self, iterable: AsyncGenerator[bytes, None] | Iterable) -> None:
105+
def __init__(self, iterable: AsyncIterable[bytes] | Iterable) -> None:
106106
self.iter: AsyncGenerator[bytes, None]
107107
if isasyncgen(iterable):
108108
self.iter = iterable
109109
elif isgenerator(iterable):
110110
self.iter = run_sync_iterable(iterable)
111-
else:
112-
111+
elif isinstance(iterable, AsyncIterable):
113112
async def _aiter() -> AsyncGenerator[bytes, None]:
114-
for data in iterable: # type: ignore
113+
async for data in iterable:
115114
yield data
116-
117115
self.iter = _aiter()
116+
elif isinstance(iterable, Iterable):
117+
async def _aiter() -> AsyncGenerator[bytes, None]:
118+
for data in iterable:
119+
yield data
120+
self.iter = _aiter()
121+
else:
122+
raise ValueError("unreachable?")
118123

119124
async def __aenter__(self) -> IterableBody:
120125
return self
@@ -262,7 +267,7 @@ class Response(SansIOResponse):
262267

263268
def __init__(
264269
self,
265-
response: ResponseBody | AnyStr | Iterable | None = None,
270+
response: ResponseBody | AnyStr | Iterable | AsyncIterable | None = None,
266271
status: int | None = None,
267272
headers: dict | Headers | None = None,
268273
mimetype: str | None = None,

0 commit comments

Comments
 (0)