fix: Update push_data and user_data annotation with JsonSerializable instead of Any#1889
fix: Update push_data and user_data annotation with JsonSerializable instead of Any#1889Mantisus wants to merge 4 commits into
push_data and user_data annotation with JsonSerializable instead of Any#1889Conversation
vdusek
left a comment
There was a problem hiding this comment.
Could you please try using this type:
JsonSerializable = dict[str, 'JsonSerializable'] | list['JsonSerializable'] | str | int | float | bool | None
"""Recursive type for JSON-serializable values - primitives plus objects and arrays with JSON-serializable contents.
Based on the definition discussed in https://github.com/python/typing/issues/182.
"""All major type checkers support recursive types now, so we can finally type this correctly. I recently made the same change in the API client as well - https://github.com/apify/apify-client-python/blob/master/src/apify_client/_types.py#L30C1-L34C4.
vdusek
left a comment
There was a problem hiding this comment.
The point of a better JsonSerializable type should be that it lets us type its various usages more accurately and with less complexity. Here are a few examples:
vdusek
left a comment
There was a problem hiding this comment.
Also see data field in the DatasetItemDb:
data: Mapped[list[dict[str, Any]] | dict[str, Any]] = mapped_column(JsonField, nullable=False)=>
data: Mapped[dict[str, JsonSerializable]] = mapped_column(JsonField, nullable=False)
|
vdusek
left a comment
There was a problem hiding this comment.
LGTM, just before merging, could you please prepare a draft PR to the SDK with
dependencies = [
# ...
"crawlee @ git+https://github.com/apify/crawlee-python.git@master",
# ...
]so we can make sure the new typing doesn't cause any issues there?
Description
Anywith explicitJsonSerializabletype forpush_dataanduser_dataparameters.Issues
push_dataannotations to useJsonSerializabletype #1191