1414 import json
1515 import logging
1616 import re
17- from collections .abc import Awaitable , Coroutine , Sequence
17+ from collections .abc import Awaitable , Coroutine , MutableMapping , Sequence
1818
1919 from typing_extensions import NotRequired , Required , Self , Unpack
2020
2727 from crawlee .storage_clients import StorageClient
2828 from crawlee .storages import KeyValueStore
2929
30- # Workaround for https://github.com/pydantic/pydantic/issues/9445
31- J = TypeVar ('J' , bound = 'JsonSerializable' )
32- JsonSerializable = list [J ] | dict [str , J ] | str | bool | int | float | None
30+ JsonSerializable = dict [str , 'JsonSerializable' ] | list ['JsonSerializable' ] | str | int | float | bool | None
3331else :
3432 from pydantic import JsonValue as JsonSerializable
3533
@@ -198,7 +196,7 @@ class PushDataKwargs(TypedDict):
198196
199197
200198class PushDataFunctionCall (PushDataKwargs ):
201- data : list [ dict [str , Any ]] | dict [str , Any ]
199+ data : Sequence [ Mapping [str , JsonSerializable ]] | Mapping [str , JsonSerializable ]
202200 dataset_id : str | None
203201 dataset_name : str | None
204202 dataset_alias : str | None
@@ -300,7 +298,7 @@ async def add_requests(
300298
301299 async def push_data (
302300 self ,
303- data : list [ dict [str , Any ]] | dict [str , Any ],
301+ data : Sequence [ Mapping [str , JsonSerializable ]] | Mapping [str , JsonSerializable ],
304302 dataset_id : str | None = None ,
305303 dataset_name : str | None = None ,
306304 dataset_alias : str | None = None ,
@@ -392,7 +390,7 @@ def __call__(
392390 selector : str | None = None ,
393391 attribute : str | None = None ,
394392 label : str | None = None ,
395- user_data : dict [str , Any ] | None = None ,
393+ user_data : Mapping [str , JsonSerializable ] | None = None ,
396394 transform_request_function : Callable [[RequestOptions ], RequestOptions | RequestTransformAction ] | None = None ,
397395 rq_id : str | None = None ,
398396 rq_name : str | None = None ,
@@ -417,7 +415,7 @@ def __call__(
417415 selector : str | None = None ,
418416 attribute : str | None = None ,
419417 label : str | None = None ,
420- user_data : dict [str , Any ] | None = None ,
418+ user_data : Mapping [str , JsonSerializable ] | None = None ,
421419 transform_request_function : Callable [[RequestOptions ], RequestOptions | RequestTransformAction ] | None = None ,
422420 requests : Sequence [str | Request ] | None = None ,
423421 rq_id : str | None = None ,
@@ -465,7 +463,7 @@ def __call__(
465463 selector : str = 'a' ,
466464 attribute : str = 'href' ,
467465 label : str | None = None ,
468- user_data : dict [str , Any ] | None = None ,
466+ user_data : Mapping [str , JsonSerializable ] | None = None ,
469467 transform_request_function : Callable [[RequestOptions ], RequestOptions | RequestTransformAction ] | None = None ,
470468 ** kwargs : Unpack [EnqueueLinksKwargs ],
471469 ) -> Coroutine [None , None , list [Request ]]:
@@ -543,7 +541,7 @@ class PushDataFunction(Protocol):
543541
544542 def __call__ (
545543 self ,
546- data : list [ dict [str , Any ]] | dict [str , Any ],
544+ data : Sequence [ Mapping [str , JsonSerializable ]] | Mapping [str , JsonSerializable ],
547545 dataset_id : str | None = None ,
548546 dataset_name : str | None = None ,
549547 dataset_alias : str | None = None ,
@@ -616,8 +614,8 @@ class UseStateFunction(Protocol):
616614
617615 def __call__ (
618616 self ,
619- default_value : dict [str , JsonSerializable ] | None = None ,
620- ) -> Coroutine [None , None , dict [str , JsonSerializable ]]:
617+ default_value : MutableMapping [str , JsonSerializable ] | None = None ,
618+ ) -> Coroutine [None , None , MutableMapping [str , JsonSerializable ]]:
621619 """Call dunder method.
622620
623621 Args:
0 commit comments