From 73ae4bd2058fc1540e9a881c1f10269d76efdef0 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Tue, 21 Apr 2026 09:03:44 +0200 Subject: [PATCH] refactor: Improve JsonSerializable type to be recursive Replace the loose `dict[str, Any] | list[Any]` variants with recursive references so nested JSON values are now properly typed instead of falling back to `Any`. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/apify_client/_types.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/apify_client/_types.py b/src/apify_client/_types.py index d3af93d0..f9af89e6 100644 --- a/src/apify_client/_types.py +++ b/src/apify_client/_types.py @@ -3,7 +3,7 @@ import json from base64 import b64encode from datetime import timedelta -from typing import Annotated, Any, Literal +from typing import Annotated, Literal from pydantic import AnyUrl, BaseModel, ConfigDict, Field, RootModel, model_validator @@ -16,9 +16,10 @@ A `timedelta` overrides the timeout for this call, and `'no_timeout'` disables the timeout entirely. """ -JsonSerializable = str | int | float | bool | None | dict[str, Any] | list[Any] -"""Type for representing json-serializable values. It's close enough to the real thing supported by json.parse. -It was suggested in a discussion with (and approved by) Guido van Rossum, so I'd consider it correct enough. +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. """