Skip to content

Commit 6b8001e

Browse files
authored
refactor: Improve JsonSerializable type to be recursive (#745)
## Summary Replace the loose `dict[str, Any] | list[Any]` variants of `JsonSerializable` with recursive references so nested JSON values are properly typed instead of falling back to `Any`. Based on the definition discussed in python/typing#182.
1 parent 10d0227 commit 6b8001e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/apify_client/_types.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
from base64 import b64encode
55
from datetime import timedelta
6-
from typing import Annotated, Any, Literal
6+
from typing import Annotated, Literal
77

88
from pydantic import AnyUrl, BaseModel, ConfigDict, Field, RootModel, model_validator
99

@@ -16,9 +16,10 @@
1616
A `timedelta` overrides the timeout for this call, and `'no_timeout'` disables the timeout entirely.
1717
"""
1818

19-
JsonSerializable = str | int | float | bool | None | dict[str, Any] | list[Any]
20-
"""Type for representing json-serializable values. It's close enough to the real thing supported by json.parse.
21-
It was suggested in a discussion with (and approved by) Guido van Rossum, so I'd consider it correct enough.
19+
JsonSerializable = dict[str, 'JsonSerializable'] | list['JsonSerializable'] | str | int | float | bool | None
20+
"""Recursive type for JSON-serializable values - primitives plus objects and arrays with JSON-serializable contents.
21+
22+
Based on the definition discussed in https://github.com/python/typing/issues/182.
2223
"""
2324

2425

0 commit comments

Comments
 (0)