浏览代码

[ENG-3954] Treat ArrayVar.foreach index as int (#4193)

* [ENG-3954] Treat ArrayVar.foreach index as int

* foreach: convert return value to a Var

When the value returned from the foreach is not hashable (mutable type), then
it will raise an exception if it is not first converted to a LiteralVar.
Masen Furer 7 月之前
父节点
当前提交
e14c79d57d
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      reflex/vars/sequence.py

+ 5 - 2
reflex/vars/sequence.py

@@ -1155,7 +1155,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE]):
             function_var = ArgsFunctionOperation.create(tuple(), return_value)
         else:
             # generic number var
-            number_var = Var("").to(NumberVar)
+            number_var = Var("").to(NumberVar, int)
 
             first_arg_type = self[number_var]._var_type
 
@@ -1167,7 +1167,10 @@ class ArrayVar(Var[ARRAY_VAR_TYPE]):
                 _var_type=first_arg_type,
             ).guess_type()
 
-            function_var = ArgsFunctionOperation.create((arg_name,), fn(first_arg))
+            function_var = ArgsFunctionOperation.create(
+                (arg_name,),
+                Var.create(fn(first_arg)),
+            )
 
         return map_array_operation(self, function_var)