Repository navigation
fix(vars): accept a frozenset as an array literal - #7622
Conversation
`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
[Medium impact] The PR appears safe to merge; the previous callback typing issue is fixed. SummaryAdds
Reviews (2) · Last reviewed commit: "fix(vars): infer a frozenset literal's e..." · Reviewed by Greptile |
There was a problem hiding this comment.
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
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
Merging this PR will not alter performance
|
…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>
All Submissions:
Type of change
Description
LiteralVar.createrendered asetas an array but rejected afrozenset:A frozen set now behaves like a set at runtime:
frozensetis registered alongsidesetonArrayVar, so the literal renders as[1, 2, 3];figure_out_typeinfersfrozenset[T]likeset[T], and the array index helper reads the element type out of it, sorx.foreachand 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_TYPEis bound toSequence) and theLiteralVar.createoverloads, which don't coversettoday either, andSequence-typed props, which reject asetvar as well. Those are a broader typing change than this parity fix.Changes To Core Features:
The array rendering parametrization in
tests/units/test_var.pygains afrozensetcase, andtest_frozenset_literal_types_its_elementschecks the inferred type, a typed element on indexing, and a typed.mapcallback.ruff,pyrighton the touched files, andpytest tests/units/test_var.pypass.🤖 Generated with Claude Code
https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD