Просмотр исходного кода

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
Khaleel Al-Adhami 3 недель назад
Родитель
Сommit
f2565e049b
2 измененных файлов с 6 добавлено и 6 удалено
  1. 2 6
      reflex/utils/types.py
  2. 4 0
      reflex/vars/base.py

+ 2 - 6
reflex/utils/types.py

@@ -149,16 +149,12 @@ def get_type_hints(obj: Any) -> dict[str, Any]:
     return get_type_hints_og(obj)
     return get_type_hints_og(obj)
 
 
 
 
-def _unionize(args: list[GenericType]) -> type:
+def _unionize(args: list[GenericType]) -> GenericType:
     if not args:
     if not args:
         return Any  # pyright: ignore [reportReturnType]
         return Any  # pyright: ignore [reportReturnType]
     if len(args) == 1:
     if len(args) == 1:
         return args[0]
         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:
 def unionize(*args: GenericType) -> type:

+ 4 - 0
reflex/vars/base.py

@@ -1782,6 +1782,10 @@ def figure_out_type(value: Any) -> types.GenericType:
     if isinstance(value, set):
     if isinstance(value, set):
         return set[unionize(*(figure_out_type(v) for v in value))]
         return set[unionize(*(figure_out_type(v) for v in value))]
     if isinstance(value, tuple):
     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)), ...]
         return tuple[unionize(*(figure_out_type(v) for v in value)), ...]
     if isinstance(value, Mapping):
     if isinstance(value, Mapping):
         if not value:
         if not value: