Browse Source

allow set in var.contains (#3113)

* allow set in var.contains

* fix UT
Martin Xu 1 year ago
parent
commit
c567334c92
2 changed files with 2 additions and 2 deletions
  1. 1 1
      reflex/vars.py
  2. 1 1
      tests/test_var.py

+ 1 - 1
reflex/vars.py

@@ -1340,7 +1340,7 @@ class Var:
         Returns:
             A var representing the contain check.
         """
-        if not (types._issubclass(self._var_type, Union[dict, list, tuple, str])):
+        if not (types._issubclass(self._var_type, Union[dict, list, tuple, str, set])):
             raise TypeError(
                 f"Var {self._var_full_name} of type {self._var_type} does not support contains check."
             )

+ 1 - 1
tests/test_var.py

@@ -415,6 +415,7 @@ def test_basic_operations(TestObj):
     "var, expected",
     [
         (v([1, 2, 3]), "[1, 2, 3]"),
+        (v(set([1, 2, 3])), "[1, 2, 3]"),
         (v(["1", "2", "3"]), '["1", "2", "3"]'),
         (BaseVar(_var_name="foo", _var_type=list)._var_set_state("state"), "state.foo"),
         (BaseVar(_var_name="foo", _var_type=list), "foo"),
@@ -918,7 +919,6 @@ def test_unsupported_types_for_reverse(var):
         BaseVar(_var_name="var", _var_type=int),
         BaseVar(_var_name="var", _var_type=float),
         BaseVar(_var_name="var", _var_type=bool),
-        BaseVar(_var_name="var", _var_type=set),
         BaseVar(_var_name="var", _var_type=None),
     ],
 )