Skip to content

Commit

Permalink
[ENG-3954] Treat ArrayVar.foreach index as int (#4193)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
masenf committed Oct 17, 2024
1 parent 542382c commit a6b2e64
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions reflex/vars/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ def foreach(self, fn: Any):
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

Expand All @@ -1167,7 +1167,10 @@ def foreach(self, fn: Any):
_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)

Expand Down

0 comments on commit a6b2e64

Please sign in to comment.