@@ -91,14 +91,14 @@ class IterableListPage(ListPage[T], Iterable[T], Generic[T]):
9191 yields individual items and performs additional API calls as needed to fetch further pages.
9292 """
9393
94- def __init__ (self , first_page : HasItems [T ], iterator : Iterator [T ]) -> None :
94+ def __init__ (self , first_page : HasItems [T ], get_iterator : Callable [[], Iterator [T ] ]) -> None :
9595 """Initialize a page wrapper from a Pydantic paginated model and an iterator over all items."""
9696 super ().__init__ (first_page )
97- self ._iterator = iterator
97+ self ._get_iterator = get_iterator
9898
9999 def __iter__ (self ) -> Iterator [T ]:
100100 """Return an iterator over all items across pages, fetching additional pages as needed."""
101- return self ._iterator
101+ return self ._get_iterator ()
102102
103103
104104@docs_group ('Other' )
@@ -113,15 +113,15 @@ class IterableListPageAsync(AsyncIterable[T], Generic[T]):
113113 def __init__ (
114114 self ,
115115 awaitable_first_page : Callable [[], Awaitable [ListPage [T ]]],
116- async_iterator : AsyncIterator [T ],
116+ get_async_iterator : Callable [[], AsyncIterator [T ] ],
117117 ) -> None :
118118 """Initialize with a factory that creates the awaitable on demand and the async iterator over items."""
119119 self ._awaitable_first_page = awaitable_first_page
120- self ._async_iterator = async_iterator
120+ self ._get_async_iterator = get_async_iterator
121121
122122 def __aiter__ (self ) -> AsyncIterator [T ]:
123123 """Return an asynchronous iterator over all items across pages."""
124- return self ._async_iterator
124+ return self ._get_async_iterator ()
125125
126126 def __await__ (self ) -> Generator [Any , Any , ListPage [T ]]:
127127 """Return an awaitable that resolves to an `IterableListPage` containing the first page."""
@@ -161,7 +161,7 @@ def build_iterable_list_page(
161161
162162 first_page = callback (** {** kwargs , 'limit' : _min_for_limit_param (kwargs .get ('limit' ), chunk_size )})
163163
164- def iterator () -> Iterator [T ]:
164+ def get_iterator () -> Iterator [T ]:
165165 current_page = first_page
166166 yield from current_page .items
167167
@@ -176,7 +176,7 @@ def iterator() -> Iterator[T]:
176176 yield from current_page .items
177177 fetched_items += getattr (current_page , 'count' , len (current_page .items ))
178178
179- return IterableListPage (first_page , iterator () )
179+ return IterableListPage (first_page , get_iterator )
180180
181181
182182def build_iterable_list_page_async (
@@ -196,7 +196,7 @@ def build_iterable_list_page_async(
196196 # Can be awaited multiple times with same result, but not scheduled at this time yet, as it might be pre-emptive.
197197 fetch_first_page = _LazyTask (callback (** {** kwargs , 'limit' : _min_for_limit_param (kwargs .get ('limit' ), chunk_size )}))
198198
199- async def async_iterator () -> AsyncIterator [Any ]:
199+ async def get_async_iterator () -> AsyncIterator [Any ]:
200200 current_page = await fetch_first_page
201201 for item in current_page .items :
202202 yield item
@@ -217,7 +217,7 @@ async def wrap_first_page() -> ListPage[Any]:
217217 first_page = await fetch_first_page
218218 return ListPage (first_page )
219219
220- return IterableListPageAsync (wrap_first_page , async_iterator () )
220+ return IterableListPageAsync (wrap_first_page , get_async_iterator )
221221
222222
223223def build_cursor_iterable_list_page (
@@ -242,7 +242,7 @@ def build_cursor_iterable_list_page(
242242 first_limit = _min_for_limit_param (limit , effective_chunk )
243243 first_page = callback (** {** kwargs , cursor_param : initial_cursor , 'limit' : first_limit })
244244
245- def iterator () -> Iterator [Any ]:
245+ def get_iterator () -> Iterator [Any ]:
246246 current_page = first_page
247247 yield from current_page .items
248248
@@ -257,7 +257,7 @@ def iterator() -> Iterator[Any]:
257257 fetched += len (current_page .items )
258258 next_cursor = getattr (current_page , f'next_{ cursor_param } ' )
259259
260- return IterableListPage (first_page , iterator () )
260+ return IterableListPage (first_page , get_iterator )
261261
262262
263263def build_cursor_iterable_list_page_async (
@@ -282,7 +282,7 @@ def build_cursor_iterable_list_page_async(
282282 # Can be awaited multiple times with same result, but not scheduled at this time yet, as it might be pre-emptive.
283283 fetch_first_page = _LazyTask (callback (** {** kwargs , cursor_param : initial_cursor , 'limit' : first_limit }))
284284
285- async def async_iterator () -> AsyncIterator [Any ]:
285+ async def get_async_iterator () -> AsyncIterator [Any ]:
286286 current_page = await fetch_first_page
287287 for item in current_page .items :
288288 yield item
@@ -302,4 +302,4 @@ async def async_iterator() -> AsyncIterator[Any]:
302302 async def wrap_first_page () -> ListPage [Any ]:
303303 return ListPage (await fetch_first_page )
304304
305- return IterableListPageAsync (wrap_first_page , async_iterator () )
305+ return IterableListPageAsync (wrap_first_page , get_async_iterator )
0 commit comments