Repository navigation
Description
Summary
Python set values are not well supported as vars today. ArrayVar registers set among its Python types, so a set-typed state var or a set literal is treated as a plain sequence: it renders as a JS array and only array operations (length, indexing, .map, contains) are available. frozenset is not accepted at all (LiteralVar.create(frozenset(...)) raises TypeError). #7622 briefly added frozenset to ArrayVar and was reverted in #7632, because widening the array types is the wrong direction.
Proposal
Add a dedicated SetVar (and LiteralSetVar) for set[T] and frozenset[T] that compiles to a real JS Set and exposes set operations rather than array operations:
- membership:
contains/has - size:
length/size - combination:
union,intersection,difference,symmetric_difference,issubset,issuperset - conversion:
to_array(forrx.foreachand anything that wants a sequence) - the operations should return
SetVarorBoolVaras appropriate, with element typeTpreserved statically, soLiteralVar.create({"a"})is typed asSetVar[set[str]]rather than a plainVar.
Once SetVar exists, remove set from ArrayVar's Python types and make figure_out_type / _determine_value_of_array_index route set and frozenset to the new class.
Prerequisite: rehydrating Set on the frontend
State values travel to the frontend as JSON, and serialize_set turns a set into a list. There is no mechanism today to turn a JSON-encoded value back into a real Set object on the frontend, so a set-typed state var arrives as an array and a SetVar operating on it would have nothing to call .has() on.
Before SetVar can work on state vars, the frontend needs a way to rehydrate JSON values as Set objects, driven by the var's declared type (for example a per-var deserializer applied in the state delta handler, or a tagged encoding chosen on the backend). Design that first; SetVar on literals alone is not very useful.
Not in scope
Whether a set var should satisfy a Sequence[...]-typed component prop is a separate question (typehint_issubclass / _isinstance in reflex_base/utils/types.py). With SetVar the answer is probably "no, call .to_array()", but decide it separately.
Longer-horizon item; no implementation planned yet.
Activity
linear-code commentedon Oct 20, 2026
ENG-13480
Huzi-06 commentedon Oct 21, 2026
Hi! I’d like to take this one if it’s still available.
[-]Cover set and frozenset in the static array var types[/-][+]Add a `SetVar` backed by the JS `Set` object[/+]Revert "fix(vars): accept a frozenset as an array literal (#7622)" (#…
feat(vars): add SetVar for set and frozenset vars (reflex-dev#7642)