|
3 | 3 | import asyncio |
4 | 4 | import warnings |
5 | 5 | from logging import getLogger |
6 | | -from typing import TYPE_CHECKING, Any |
| 6 | +from typing import TYPE_CHECKING |
7 | 7 |
|
8 | 8 | from typing_extensions import override |
9 | 9 |
|
|
16 | 16 | from apify.storage_clients._ppe_dataset_mixin import DatasetClientPpeMixin |
17 | 17 |
|
18 | 18 | if TYPE_CHECKING: |
19 | | - from collections.abc import AsyncIterator |
| 19 | + from collections.abc import AsyncIterator, Mapping, Sequence |
20 | 20 |
|
21 | 21 | from apify_client.clients import DatasetClientAsync |
22 | 22 | from crawlee._types import JsonSerializable |
@@ -137,13 +137,13 @@ async def drop(self) -> None: |
137 | 137 | await self._api_client.delete() |
138 | 138 |
|
139 | 139 | @override |
140 | | - async def push_data(self, data: list[Any] | dict[str, Any]) -> None: |
141 | | - async def payloads_generator(items: list[Any]) -> AsyncIterator[str]: |
| 140 | + async def push_data(self, data: Sequence[Mapping[str, JsonSerializable]] | Mapping[str, JsonSerializable]) -> None: |
| 141 | + async def payloads_generator(items: Sequence[Mapping[str, JsonSerializable]]) -> AsyncIterator[str]: |
142 | 142 | for index, item in enumerate(items): |
143 | 143 | yield await self._check_and_serialize(item, index) |
144 | 144 |
|
145 | 145 | async with self._charge_lock(), self._lock: |
146 | | - items = data if isinstance(data, list) else [data] |
| 146 | + items = data if self._is_sequence_of_items(data) else [data] |
147 | 147 | limit = self._compute_limit_for_push(len(items)) |
148 | 148 | items = items[:limit] |
149 | 149 |
|
@@ -211,7 +211,7 @@ async def iterate_items( |
211 | 211 | yield item |
212 | 212 |
|
213 | 213 | @classmethod |
214 | | - async def _check_and_serialize(cls, item: JsonSerializable, index: int | None = None) -> str: |
| 214 | + async def _check_and_serialize(cls, item: Mapping[str, JsonSerializable], index: int | None = None) -> str: |
215 | 215 | """Serialize a given item to JSON, checks its serializability and size against a limit. |
216 | 216 |
|
217 | 217 | Args: |
|
0 commit comments