Skip to content

Commit 8d5fafa

Browse files
committed
Review comments
1 parent 78c98cd commit 8d5fafa

19 files changed

Lines changed: 34 additions & 36 deletions

scripts/_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
(re.compile(r'\bSynchronous\b'), 'Asynchronous'),
2828
(re.compile(r'Retry a function'), 'Retry an async function'),
2929
(re.compile(r'Function to retry'), 'Async function to retry'),
30+
(re.compile(r'returned page also supports iteration: `for'), 'returned page also supports iteration: `async for'),
3031
]
3132
"""Patterns for converting sync docstrings to async docstrings."""
3233

src/apify_client/_iterable_list_page.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

182182
def 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

223223
def 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

263263
def 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)

src/apify_client/_models_generated.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3912,7 +3912,7 @@ class WebhookDispatchList(BaseModel):
39123912
extra='allow',
39133913
populate_by_name=True,
39143914
)
3915-
data: ListOfWebhookDispatches | None = None
3915+
data: ListOfWebhookDispatches
39163916

39173917

39183918
@docs_group('Models')

src/apify_client/_resource_clients/actor_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def list(
218218
) -> IterableListPageAsync[ActorShort]:
219219
"""List the Actors the user has created or used.
220220
221-
The returned page also supports iteration: `for item in client.list(...)` yields individual Actors
221+
The returned page also supports iteration: `async for item in client.list(...)` yields individual Actors
222222
and transparently fetches further pages from the API.
223223
224224
https://docs.apify.com/api/v2#/reference/actors/actor-collection/get-list-of-actors

src/apify_client/_resource_clients/actor_env_var_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(
106106
def list(self, *, timeout: Timeout = 'short') -> IterableListPageAsync[EnvVar]:
107107
"""List the available Actor environment variables.
108108
109-
The returned page also supports iteration: `for item in client.list()` yields individual environment
109+
The returned page also supports iteration: `async for item in client.list()` yields individual environment
110110
variables.
111111
112112
https://docs.apify.com/api/v2#/reference/actors/environment-variable-collection/get-list-of-environment-variables

src/apify_client/_resource_clients/actor_version_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def __init__(
146146
def list(self, *, timeout: Timeout = 'short') -> IterableListPageAsync[Version]:
147147
"""List the available Actor versions.
148148
149-
The returned page also supports iteration: `for item in client.list()` yields individual versions.
149+
The returned page also supports iteration: `async for item in client.list()` yields individual versions.
150150
151151
https://docs.apify.com/api/v2#/reference/actors/version-collection/get-list-of-versions
152152

src/apify_client/_resource_clients/build_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def list(
104104
List all Actor builds, either of a single Actor, or all user's Actors, depending on where this client
105105
was initialized from.
106106
107-
The returned page also supports iteration: `for item in client.list(...)` yields individual builds
107+
The returned page also supports iteration: `async for item in client.list(...)` yields individual builds
108108
and transparently fetches further pages from the API.
109109
110110
https://docs.apify.com/api/v2#/reference/actors/build-collection/get-list-of-builds

src/apify_client/_resource_clients/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def list_items(
828828
) -> IterableListPageAsync[dict[str, Any]]:
829829
"""List the items of the dataset.
830830
831-
The returned page also supports iteration: `for item in client.list_items(...)` yields individual
831+
The returned page also supports iteration: `async for item in client.list_items(...)` yields individual
832832
items and transparently fetches further pages from the API.
833833
834834
https://docs.apify.com/api/v2#/reference/datasets/item-collection/get-items

src/apify_client/_resource_clients/dataset_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def list(
132132
) -> IterableListPageAsync[DatasetListItem]:
133133
"""List the available datasets.
134134
135-
The returned page also supports iteration: `for item in client.list(...)` yields individual datasets
135+
The returned page also supports iteration: `async for item in client.list(...)` yields individual datasets
136136
and transparently fetches further pages from the API.
137137
138138
https://docs.apify.com/api/v2#/reference/datasets/dataset-collection/get-list-of-datasets

src/apify_client/_resource_clients/key_value_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def list_keys(
594594
) -> IterableListPageAsync[KeyValueStoreKey]:
595595
"""List the keys in the key-value store.
596596
597-
The returned page also supports iteration: `for key in client.list_keys(...)` yields individual
597+
The returned page also supports iteration: `async for key in client.list_keys(...)` yields individual
598598
keys and transparently fetches further pages using cursor-based pagination.
599599
600600
https://docs.apify.com/api/v2#/reference/key-value-stores/key-collection/get-list-of-keys

0 commit comments

Comments
 (0)