{"record":{"id":"8c2eecddd814f1d1","repo":"reflex-dev/reflex","slug":"untypedcomputedvarerror-var-name-fget-name","errorCode":null,"errorMessage":"UntypedComputedVarError(var_name=fget.__name__)","messagePattern":"UntypedComputedVarError\\(var_name=fget\\.__name__\\)","errorType":"exception","errorClass":"UntypedComputedVarError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/base.py","lineNumber":2329,"sourceCode":"            fget: The getter function.\n            initial_value: The initial value of the computed var.\n            cache: Whether to cache the computed value.\n            deps: Explicit var dependencies to track.\n            auto_deps: Whether var dependencies should be auto-determined.\n            interval: Interval at which the computed var should be updated.\n            backend: Whether the computed var is a backend var.\n            **kwargs: additional attributes to set on the instance\n\n        Raises:\n            TypeError: If the computed var dependencies are not Var instances or var names.\n            UntypedComputedVarError: If the computed var is untyped.\n        \"\"\"\n        hint = kwargs.pop(\"return_type\", None) or get_type_hints(fget).get(\n            \"return\", Any\n        )\n\n        if hint is Any:\n            raise UntypedComputedVarError(var_name=fget.__name__)\n        is_using_fget_name = \"_js_expr\" not in kwargs\n        js_expr = kwargs.pop(\"_js_expr\", fget.__name__ + FIELD_MARKER)\n        kwargs.setdefault(\"_var_type\", hint)\n\n        Var.__init__(\n            self,\n            _js_expr=js_expr,\n            _var_type=kwargs.pop(\"_var_type\"),\n            _var_data=kwargs.pop(\n                \"_var_data\",\n                VarData(field_name=fget.__name__) if is_using_fget_name else None,\n            ),\n        )\n\n        if kwargs:\n            msg = f\"Unexpected keyword arguments: {tuple(kwargs)}\"\n            raise TypeError(msg)\n","sourceCodeStart":2311,"sourceCodeEnd":2347,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/base.py#L2311-L2347","documentation":"Reflex requires every ComputedVar (a @rx.var-decorated method on a State) to have an explicit return type annotation. The constructor inspects the function's type hints; if the resolved return hint is Any — i.e. missing annotation or a plain Any — it raises UntypedComputedVarError. Reflex needs the real type to generate correct TypeScript types and frontend rendering behavior.","triggerScenarios":"Defining a computed var without a return annotation: @rx.var def full_name(self): return ..., or annotating it as -> Any. Also when the annotation cannot be resolved by get_type_hints (e.g. from __future__ import annotations with unimported/unresolvable names can degrade to Any).","commonSituations":"Porting untyped Python code into a Reflex State; quick prototypes omitting annotations; using -> Any to silence a type checker; string annotations referencing names not imported at runtime.","solutions":["Add a concrete return annotation to the computed var: def my_var(self) -> str:","Replace -> Any with the real type; if the type is genuinely dynamic, use a union or object plus explicit frontend handling","If the annotation exists but still fails, ensure all names in the annotation are importable at runtime (get_type_hints must resolve them) or pass return_type=<type> explicitly"],"exampleFix":"# before\nclass State(rx.State):\n    @rx.var\n    def full_name(self):\n        return f\"{self.first} {self.last}\"\n\n# after\nclass State(rx.State):\n    @rx.var\n    def full_name(self) -> str:\n        return f\"{self.first} {self.last}\"","handlingStrategy":"type-guard","validationCode":"import typing\n\ndef has_return_hint(fn) -> bool:\n    hints = typing.get_type_hints(fn)\n    hint = hints.get('return')\n    return hint is not None and hint is not typing.Any","typeGuard":"import typing, reflex as rx\n\ndef is_typed_computed_var(fn) -> bool:\n    hint = typing.get_type_hints(fn).get('return')\n    return hint is not None and hint is not typing.Any\n\n# usage: only apply @rx.var to functions where is_typed_computed_var(fn) is True","tryCatchPattern":"from reflex.vars import UntypedComputedVarError\n\ntry:\n    apply_var = rx.var(deps=[])(fn)\nexcept UntypedComputedVarError:\n    fn.__annotations__['return'] = str\n    apply_var = rx.var(deps=[])(fn)","preventionTips":["Annotate every @rx.var method with a concrete return type","Enable pyright/mypy strict mode so unannotated functions are flagged at authoring time","Avoid -> Any on computed vars; use explicit unions or object plus serializers"],"tags":["reflex","computed-var","type-annotation","state","typing"],"backgroundTag":"missing-return-type-annotation","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}