Skip to content

Commit f2565e0

Browse files
authored
treat small tuples different with figure out type (#5161)
* treat small tuples different with figure out type * use tuple because i don't know what i'm doing
1 parent f4364af commit f2565e0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

reflex/utils/types.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,12 @@ def get_type_hints(obj: Any) -> dict[str, Any]:
149149
return get_type_hints_og(obj)
150150

151151

152-
def _unionize(args: list[GenericType]) -> type:
152+
def _unionize(args: list[GenericType]) -> GenericType:
153153
if not args:
154154
return Any # pyright: ignore [reportReturnType]
155155
if len(args) == 1:
156156
return args[0]
157-
# We are bisecting the args list here to avoid hitting the recursion limit
158-
# In Python versions >= 3.11, we can simply do `return Union[*args]`
159-
midpoint = len(args) // 2
160-
first_half, second_half = args[:midpoint], args[midpoint:]
161-
return Union[unionize(*first_half), unionize(*second_half)] # pyright: ignore [reportReturnType] # noqa: UP007
157+
return Union[tuple(args)] # noqa: UP007
162158

163159

164160
def unionize(*args: GenericType) -> type:

reflex/vars/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,10 @@ def figure_out_type(value: Any) -> types.GenericType:
17821782
if isinstance(value, set):
17831783
return set[unionize(*(figure_out_type(v) for v in value))]
17841784
if isinstance(value, tuple):
1785+
if not value:
1786+
return tuple[NoReturn, ...]
1787+
if len(value) <= 5:
1788+
return tuple[tuple(figure_out_type(v) for v in value)]
17851789
return tuple[unionize(*(figure_out_type(v) for v in value)), ...]
17861790
if isinstance(value, Mapping):
17871791
if not value:

0 commit comments

Comments
 (0)