Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Add a `SetVar` backed by the JS `Set` object

Abierto Apto para principiantes
#7,623 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@Huzi-06 ya está trabajando en esto.

Desde el 21/10/2026.

  • #7625 de @Huzi-06 — abierto
  • #7642 de @FarhanAliRaza — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Lee packages/reflex-base/src/reflex_base/vars/sequence.py y packages/reflex-base/src/reflex_base/vars/base.py para localizar los límites del tipo array y las sobrecargas de LiteralVar.create. Después, inspecciona tests/units/test_var.py, elimina el cast de test_frozenset_literal_types_its_elements y añade un caso de set tipado. El trabajo estará terminado cuando tanto los literales de set como los de frozenset se infieran estáticamente como arrays con sus tipos de elemento.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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 (for rx.foreach and anything that wants a sequence)
  • the operations should return SetVar or BoolVar as appropriate, with element type T preserved statically, so LiteralVar.create({"a"}) is typed as SetVar[set[str]] rather than a plain Var.

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.

Lenguaje dominante
Python
Estrellas
29k
Forks
1.8k
Merge medio
3 d 9 h
PR fusionados (30 d)
188

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de reflex-dev/reflex

Todos los issues de reflex-dev/reflex

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.