Skip to content

Commit 4e751a8

Browse files
masenfclaudeFarhanAliRaza
authored
Revert "fix(vars): accept a frozenset as an array literal (#7622)" (#7632)
This reverts commit 54c9aa6. Treating a set or frozenset as an ArrayVar is the wrong direction: sets are not sequences, and the operations users want on them (membership, add, union) are not array operations. A dedicated SetVar backed by the JS Set object is tracked in #7623 instead. Claude-Session: https://claude.ai/code/session_014RnswbLCA27Ku2CxbJs58d Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Farhan Ali Raza <62690310+FarhanAliRaza@users.noreply.github.com>
1 parent 74bcd8b commit 4e751a8

4 files changed

Lines changed: 4 additions & 24 deletions

File tree

‎packages/reflex-base/news/+frozenset-literal.bugfix.md‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎packages/reflex-base/src/reflex_base/vars/base.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ def figure_out_type(value: Any) -> types.GenericType:
21742174
Returns:
21752175
The type of the value.
21762176
"""
2177-
if isinstance(value, (list, set, frozenset, tuple, Mapping, Var)):
2177+
if isinstance(value, (list, set, tuple, Mapping, Var)):
21782178
if isinstance(value, Var):
21792179
return value._var_type
21802180
if has_args(value_type := type(value)):
@@ -2183,11 +2183,8 @@ def figure_out_type(value: Any) -> types.GenericType:
21832183
if not value:
21842184
return Sequence[NoReturn]
21852185
return Sequence[unionize(*{figure_out_type(v) for v in value[:100]})]
2186-
if isinstance(value, (set, frozenset)):
2187-
element_type = unionize(*{figure_out_type(v) for v in value})
2188-
if isinstance(value, frozenset):
2189-
return frozenset[element_type]
2190-
return set[element_type]
2186+
if isinstance(value, set):
2187+
return set[unionize(*{figure_out_type(v) for v in value})]
21912188
if isinstance(value, tuple):
21922189
if not value:
21932190
return tuple[NoReturn, ...]

‎packages/reflex-base/src/reflex_base/vars/sequence.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
VALUE_TYPE = TypeVar("VALUE_TYPE")
6464

6565

66-
class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(Sequence, set, frozenset)):
66+
class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(Sequence, set)):
6767
"""Base class for immutable array vars."""
6868

6969
def join(self, sep: StringVar | str = "") -> StringVar:
@@ -1920,7 +1920,6 @@ def _determine_value_of_array_index(
19201920
Iterable,
19211921
list,
19221922
set,
1923-
frozenset,
19241923
collections.abc.Sequence,
19251924
collections.abc.Iterable,
19261925
]:

‎tests/units/test_var.py‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
ConcatVarOperation,
5252
LiteralArrayVar,
5353
LiteralStringVar,
54-
StringVar,
5554
)
5655

5756
import reflex as rx
@@ -422,19 +421,6 @@ def test_date_comparison_uses_compare_datetime():
422421
assert str(lhs == rhs) == '(compareDatetime("2024-01-01", "2024-01-02") === 0)'
423422

424423

425-
def test_frozenset_literal_types_its_elements():
426-
"""A frozen set literal infers its element type like a set does."""
427-
# The static array bound is Sequence, which no set satisfies; see the PR.
428-
var = cast(ArrayVar, v(frozenset({"a"})))
429-
430-
assert var._var_type == frozenset[str]
431-
assert isinstance(var[0], StringVar)
432-
assert re.fullmatch(
433-
r'\["a"\]\.map\(\(\((\w+)\) => \1\.toUpperCase\(\)\)\)',
434-
str(var.map(lambda item: item.upper())),
435-
)
436-
437-
438424
def test_datetime_equality_with_other_type_uses_default_comparison():
439425
value = v(datetime(2024, 1, 1))
440426
expected_equality = (
@@ -450,7 +436,6 @@ def test_datetime_equality_with_other_type_uses_default_comparison():
450436
[
451437
(v([1, 2, 3]), "[1, 2, 3]"),
452438
(v({1, 2, 3}), "[1, 2, 3]"),
453-
(v(frozenset({1, 2, 3})), "[1, 2, 3]"),
454439
(v(["1", "2", "3"]), '["1", "2", "3"]'),
455440
(
456441
Var(_js_expr="foo")._var_set_state("state").to(list),

0 commit comments

Comments
 (0)