fix(vars): accept a frozenset as an array literal
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