@@ -102,19 +102,24 @@ async def __anext__(self) -> bytes:
102
102
103
103
104
104
class IterableBody (ResponseBody ):
105
- def __init__ (self , iterable : AsyncGenerator [bytes , None ] | Iterable ) -> None :
105
+ def __init__ (self , iterable : AsyncIterable [bytes ] | Iterable ) -> None :
106
106
self .iter : AsyncGenerator [bytes , None ]
107
107
if isasyncgen (iterable ):
108
108
self .iter = iterable
109
109
elif isgenerator (iterable ):
110
110
self .iter = run_sync_iterable (iterable )
111
- else :
112
-
111
+ elif isinstance (iterable , AsyncIterable ):
113
112
async def _aiter () -> AsyncGenerator [bytes , None ]:
114
- for data in iterable : # type: ignore
113
+ async for data in iterable :
115
114
yield data
116
-
117
115
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?" )
118
123
119
124
async def __aenter__ (self ) -> IterableBody :
120
125
return self
@@ -262,7 +267,7 @@ class Response(SansIOResponse):
262
267
263
268
def __init__ (
264
269
self ,
265
- response : ResponseBody | AnyStr | Iterable | None = None ,
270
+ response : ResponseBody | AnyStr | Iterable | AsyncIterable | None = None ,
266
271
status : int | None = None ,
267
272
headers : dict | Headers | None = None ,
268
273
mimetype : str | None = None ,
0 commit comments