reflex-dev/reflex · error · UntypedComputedVarError
UntypedComputedVarError(var_name=fget.__name__)
Error message
UntypedComputedVarError(var_name=fget.__name__)
What it means
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.
Source
Thrown at packages/reflex-base/src/reflex_base/vars/base.py:2329
fget: The getter function.
initial_value: The initial value of the computed var.
cache: Whether to cache the computed value.
deps: Explicit var dependencies to track.
auto_deps: Whether var dependencies should be auto-determined.
interval: Interval at which the computed var should be updated.
backend: Whether the computed var is a backend var.
**kwargs: additional attributes to set on the instance
Raises:
TypeError: If the computed var dependencies are not Var instances or var names.
UntypedComputedVarError: If the computed var is untyped.
"""
hint = kwargs.pop("return_type", None) or get_type_hints(fget).get(
"return", Any
)
if hint is Any:
raise UntypedComputedVarError(var_name=fget.__name__)
is_using_fget_name = "_js_expr" not in kwargs
js_expr = kwargs.pop("_js_expr", fget.__name__ + FIELD_MARKER)
kwargs.setdefault("_var_type", hint)
Var.__init__(
self,
_js_expr=js_expr,
_var_type=kwargs.pop("_var_type"),
_var_data=kwargs.pop(
"_var_data",
VarData(field_name=fget.__name__) if is_using_fget_name else None,
),
)
if kwargs:
msg = f"Unexpected keyword arguments: {tuple(kwargs)}"
raise TypeError(msg)
View on GitHub (pinned to 45b8ed5ab7)
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
Example fix
# before
class State(rx.State):
@rx.var
def full_name(self):
return f"{self.first} {self.last}"
# after
class State(rx.State):
@rx.var
def full_name(self) -> str:
return f"{self.first} {self.last}" Defensive patterns
Strategy: type-guard
Validate before calling
import typing
def has_return_hint(fn) -> bool:
hints = typing.get_type_hints(fn)
hint = hints.get('return')
return hint is not None and hint is not typing.Any Type guard
import typing, reflex as rx
def is_typed_computed_var(fn) -> bool:
hint = typing.get_type_hints(fn).get('return')
return hint is not None and hint is not typing.Any
# usage: only apply @rx.var to functions where is_typed_computed_var(fn) is True Try / catch
from reflex.vars import UntypedComputedVarError
try:
apply_var = rx.var(deps=[])(fn)
except UntypedComputedVarError:
fn.__annotations__['return'] = str
apply_var = rx.var(deps=[])(fn) Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- ComputedVar dependencies must be Var instances or var names
- ComputedVar dependencies must be Var instances with a state
- Cannot determine dependencies in fetched state {local_name!r
- Could not foreach over var `{iterable!s}` of type Any. (If y
- Annotation of the computed var assigned to the data field sh
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/8c2eecddd814f1d1.
Report an issue: GitHub.