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 authored Oct 17, 2024
1 parent 101fb1b commit e14c79d
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 e14c79d

Please sign in to comment.