diff --git a/reflex/utils/types.py b/reflex/utils/types.py index 82d89543a24..67e12012d9e 100644 --- a/reflex/utils/types.py +++ b/reflex/utils/types.py @@ -149,16 +149,12 @@ def get_type_hints(obj: Any) -> dict[str, Any]: return get_type_hints_og(obj) -def _unionize(args: list[GenericType]) -> type: +def _unionize(args: list[GenericType]) -> GenericType: if not args: return Any # pyright: ignore [reportReturnType] if len(args) == 1: return args[0] - # We are bisecting the args list here to avoid hitting the recursion limit - # In Python versions >= 3.11, we can simply do `return Union[*args]` - midpoint = len(args) // 2 - first_half, second_half = args[:midpoint], args[midpoint:] - return Union[unionize(*first_half), unionize(*second_half)] # pyright: ignore [reportReturnType] # noqa: UP007 + return Union[tuple(args)] # noqa: UP007 def unionize(*args: GenericType) -> type: diff --git a/reflex/vars/base.py b/reflex/vars/base.py index 694492ecdbe..b9909908baf 100644 --- a/reflex/vars/base.py +++ b/reflex/vars/base.py @@ -1768,6 +1768,10 @@ def figure_out_type(value: Any) -> types.GenericType: if isinstance(value, set): return set[unionize(*(figure_out_type(v) for v in value))] if isinstance(value, tuple): + if not value: + return tuple[NoReturn, ...] + if len(value) <= 5: + return tuple[tuple(figure_out_type(v) for v in value)] return tuple[unionize(*(figure_out_type(v) for v in value)), ...] if isinstance(value, Mapping): if not value: