Skip to content

Pyright types an optional set or list computed var as ComputedVar, not SetVar or ArrayVar #7827

Closed

Description

@FarhanAliRaza

A computed var that returns an optional set or list has no ComputedVar.__get__ overload. Pyright types it as ComputedVar[...], not as SetVar or ArrayVar, so a set or array operation on it is a type error. At runtime the var works. A state field with the same type works in pyright too.

Repro

import reflex as rx


class S(rx.State):
    field: rx.Field[set[str] | None] = rx.field(None)

    @rx.var
    def opt_set(self) -> set[str] | None:
        return None

    @rx.var
    def opt_list(self) -> list[str] | None:
        return None


reveal_type(S.field)     # SetVar[set[str]]
reveal_type(S.opt_set)   # ComputedVar[set[str] | None]
reveal_type(S.opt_list)  # ComputedVar[list[str] | None]
S.opt_set.union({"a"})   # error: Cannot access attribute "union" (reportAttributeAccessIssue)

Expected

S.opt_set types as SetVar and S.opt_list as ArrayVar, the same as a non-optional computed var (-> set[str] gives SetVar[set[str]]).

Suggested fix

Add __get__ overloads for set[T] | None, frozenset[T] | None and list[T] | None to ComputedVar and AsyncComputedVar in reflex_base/vars/base.py, next to the existing set[LIST_INSIDE] overloads.

Found in #7800.

Activity

  1. linear-code commented on Nov 11, 2026

    @linear-code
  2. added a commit that references this issue on Nov 11, 2026
    c9f48bb
  3. added a commit that references this issue on Nov 11, 2026
    81de29f
  4. added a commit that references this issue on Nov 11, 2026
    384b63f
  5. added
    release-train
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    release-train

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions