Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions reflex/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions reflex/vars/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading