@@ -144,7 +144,7 @@ def build_iterable_list_page(
144144 The `total` field from the first page is not trusted for stopping iteration because it may change between calls;
145145 iteration stops when a page has no items or when the user-requested `limit` has been reached.
146146
147- The `count` field does not count objects returned, but object scanned by the API. For example when using filters,
147+ The `count` field does not count objects returned, but objects scanned by the API. For example when using filters,
148148 returned items can be smaller than `count`. Therefore, `count` should be used for correct offset calculation if
149149 available.
150150
@@ -213,9 +213,9 @@ async def async_iterator() -> AsyncIterator[Any]:
213213 yield item
214214 fetched_items += getattr (current_page , 'count' , len (current_page .items ))
215215
216- async def wrap_first_page () -> IterableListPage [Any ]:
216+ async def wrap_first_page () -> ListPage [Any ]:
217217 first_page = await fetch_first_page
218- return IterableListPage (first_page , iter ( first_page . items ) )
218+ return ListPage (first_page )
219219
220220 return IterableListPageAsync (wrap_first_page , async_iterator ())
221221
@@ -261,7 +261,7 @@ def iterator() -> Iterator[Any]:
261261
262262
263263def build_cursor_iterable_list_page_async (
264- callback : Callable [..., Awaitable [ HasItems [T ]]],
264+ callback : Callable [..., Coroutine [ Any , Any , HasItems [T ]]],
265265 * ,
266266 cursor_param : str ,
267267 initial_cursor : Any = None ,
@@ -279,11 +279,11 @@ def build_cursor_iterable_list_page_async(
279279 user_limit = limit or 0
280280 first_limit = _min_for_limit_param (limit , effective_chunk )
281281
282- async def fetch_first_page () -> Any :
283- return await callback (** {** kwargs , cursor_param : initial_cursor , 'limit' : first_limit })
282+ # Can be awaited multiple times with same result, but not scheduled at this time yet, as it might be pre-emptive.
283+ fetch_first_page = _LazyTask ( callback (** {** kwargs , cursor_param : initial_cursor , 'limit' : first_limit }) )
284284
285285 async def async_iterator () -> AsyncIterator [Any ]:
286- current_page = await fetch_first_page ()
286+ current_page = await fetch_first_page
287287 for item in current_page .items :
288288 yield item
289289
@@ -299,8 +299,7 @@ async def async_iterator() -> AsyncIterator[Any]:
299299 fetched += len (current_page .items )
300300 next_cursor = getattr (current_page , f'next_{ cursor_param } ' )
301301
302- async def wrap_first_page () -> IterableListPage [Any ]:
303- first_page = await fetch_first_page ()
304- return IterableListPage (first_page , iter (first_page .items ))
302+ async def wrap_first_page () -> ListPage [Any ]:
303+ return ListPage (await fetch_first_page )
305304
306305 return IterableListPageAsync (wrap_first_page , async_iterator ())
0 commit comments