reflex-dev/reflex · error · TypeError

Expected generic type of {fn_first_arg_type} to be a type.

Error message

Expected generic type of {fn_first_arg_type} to be a type.

What it means

The first argument must be a fully parameterized Var[T]; a bare Var without a generic argument gives the dispatcher nothing to dispatch on, so it raises TypeError.

Source

Thrown at packages/reflex-base/src/reflex_base/vars/base.py:3436

            raise TypeError(msg)

        fn_return_generic_args = get_args(fn_return)

        if not fn_return_generic_args:
            msg = f"Expected generic type of {fn_return} to be a type."
            raise TypeError(msg)

        arg_origin = get_origin(fn_first_arg_type) or fn_first_arg_type

        if arg_origin is not Var:
            msg = f"Expected first argument of {fn.__name__} to be a Var, got {fn_first_arg_type}."
            raise TypeError(msg)

        arg_generic_args = get_args(fn_first_arg_type)

        if not arg_generic_args:
            msg = f"Expected generic type of {fn_first_arg_type} to be a type."
            raise TypeError(msg)

        fn_return_type = fn_return_generic_args[0]

        var = (
            Var(
                field_name,
                _var_data=var_data,
                _var_type=fn_return_type,
            ).guess_type()
            if existing_var is None
            else existing_var._replace(
                _var_type=fn_return_type,
                _var_data=var_data,
                _js_expr=field_name,
            ).guess_type()
        )

        return fn(var)

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Parameterize the first argument: v: Var[int], v: Var[str], etc.

Example fix

# before
def upper(v: Var) -> Var[str]: ...
# after
def upper(v: Var[str]) -> Var[str]: ...
Defensive patterns

Strategy: type-guard

Validate before calling

from typing import get_args
assert get_args(first_param_annotation), 'Var parameter must be parameterized'

Type guard

def takes_parameterized_var(fn) -> bool:
    import inspect
    from typing import get_args
    p = next(iter(inspect.signature(fn).parameters.values()))
    return bool(get_args(p.annotation))

Prevention

When it happens

Trigger: def op(v: Var) -> Var[int] — the first parameter is annotated as bare, non-generic Var.

Common situations: Quickly annotated custom operators using plain Var.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/fa00f1838f70a6b6. Report an issue: GitHub.