Skip to content

fix(vars): accept a frozenset as an array literal - #7622

Merged
FarhanAliRaza merged 2 commits into
mainfrom
claude/literal-frozenset
Oct 20, 2026
Merged

FarhanAliRaza merged 2 commits into
mainfrom
claude/literal-frozenset

Conversation

@masenf

@masenf masenf commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Description

LiteralVar.create rendered a set as an array but rejected a frozenset:

>>> LiteralVar.create(frozenset({1, 2, 3}))
TypeError: Unsupported type <class 'frozenset'> for LiteralVar. ...

A frozen set now behaves like a set at runtime: frozenset is registered alongside set on ArrayVar, so the literal renders as [1, 2, 3]; figure_out_type infers frozenset[T] like set[T], and the array index helper reads the element type out of it, so rx.foreach and typed array operations such as .map(lambda item: item.upper()) work over it. Surfaced while reviewing #7606, which treats frozen sets as containers.

Not changed here: the static array bound (ARRAY_VAR_TYPE is bound to Sequence) and the LiteralVar.create overloads, which don't cover set today either, and Sequence-typed props, which reject a set var as well. Those are a broader typing change than this parity fix.

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

The array rendering parametrization in tests/units/test_var.py gains a frozenset case, and test_frozenset_literal_types_its_elements checks the inferred type, a typed element on indexing, and a typed .map callback. ruff, pyright on the touched files, and pytest tests/units/test_var.py pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD

`LiteralVar.create` rendered a `set` as an array but rejected a `frozenset`
with "Unsupported type". Register `frozenset` alongside `set` on `ArrayVar`,
so a frozen set renders the same way and array props accept it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD
@masenf
masenf requested a review from a team as a code owner October 20, 2026 21:11
@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous callback typing issue is fixed.

Summary

Adds frozenset support to array literals and preserves element types for indexing and callbacks.

  • Frozen sets render as arrays and keep their element types.

Reviews (2) · Last reviewed commit: "fix(vars): infer a frozenset literal's e..." · Reviewed by Greptile

Comment thread packages/reflex-base/src/reflex_base/vars/sequence.py

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/reflex-base/src/reflex_base/vars/sequence.py
Registering `frozenset` on `ArrayVar` let a frozen set render, but
`figure_out_type` returned the bare class and the array index helper did
not know `frozenset[...]`, so a callback over such a literal received an
untyped element and `.map(lambda item: item.upper())` raised
`UntypedVarError`. Infer `frozenset[T]` like `set[T]` and read the element
type out of it when indexing, so `rx.foreach` and array operations over a
frozen set are typed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD
@codspeed

codspeed Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 16 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 148 untouched benchmarks


Comparing claude/literal-frozenset (da9cc7f) with main (4be8b4d)

Open in CodSpeed

@FarhanAliRaza
FarhanAliRaza merged commit 54c9aa6 into main Oct 20, 2026
169 checks passed
@FarhanAliRaza
FarhanAliRaza deleted the claude/literal-frozenset branch October 20, 2026 22:18
masenf added a commit that referenced this pull request Oct 22, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants