{"record":{"id":"1a460acdff51add9","repo":"reflex-dev/reflex","slug":"expected-first-argument-of-fn-name-to-be-a-v","errorCode":null,"errorMessage":"Expected first argument of {fn.__name__} to be a Var, got {fn_first_arg_type}.","messagePattern":"Expected first argument of (.+?) to be a Var, got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/base.py","lineNumber":3430,"sourceCode":"        fn_return = fn_types.get(\"return\", Any)\n\n        fn_return_origin = get_origin(fn_return) or fn_return\n\n        if fn_return_origin is not Var:\n            msg = f\"Expected return type of {fn.__name__} to be a Var, got {fn_return}.\"\n            raise TypeError(msg)\n\n        fn_return_generic_args = get_args(fn_return)\n\n        if not fn_return_generic_args:\n            msg = f\"Expected generic type of {fn_return} to be a type.\"\n            raise TypeError(msg)\n\n        arg_origin = get_origin(fn_first_arg_type) or fn_first_arg_type\n\n        if arg_origin is not Var:\n            msg = f\"Expected first argument of {fn.__name__} to be a Var, got {fn_first_arg_type}.\"\n            raise TypeError(msg)\n\n        arg_generic_args = get_args(fn_first_arg_type)\n\n        if not arg_generic_args:\n            msg = f\"Expected generic type of {fn_first_arg_type} to be a type.\"\n            raise TypeError(msg)\n\n        fn_return_type = fn_return_generic_args[0]\n\n        var = (\n            Var(\n                field_name,\n                _var_data=var_data,\n                _var_type=fn_return_type,\n            ).guess_type()\n            if existing_var is None\n            else existing_var._replace(\n                _var_type=fn_return_type,","sourceCodeStart":3412,"sourceCodeEnd":3448,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/base.py#L3412-L3448","documentation":"Same validation as 188 but reports the actual offending first-argument annotation; it fires when the annotation's origin (unwrapped generic origin) is not Var, e.g. list[int] or a plain class.","triggerScenarios":"def op(v: list[int]) -> Var[int] — the first argument is a concrete generic type instead of Var[list[int]].","commonSituations":"Operators over collections annotated with the element type rather than Var[element type].","solutions":["Wrap the first argument annotation in Var[...]","For unions/optionals use Var[list[int]] not list[int] | None"],"exampleFix":"# before\ndef first(v: list[int]) -> Var[int]: ...\n# after\ndef first(v: Var[list[int]]) -> Var[int]: ...","handlingStrategy":"type-guard","validationCode":"import inspect\nfrom typing import get_origin\nfrom reflex.vars import Var\nfirst = next(iter(inspect.signature(fn).parameters.values()))\nassert (get_origin(first.annotation) or first.annotation) is Var","typeGuard":"def takes_var_first(fn) -> bool:\n    import inspect\n    from typing import get_origin\n    from reflex.vars import Var\n    p = next(iter(inspect.signature(fn).parameters.values()))\n    a = p.annotation\n    return (get_origin(a) or a) is Var","tryCatchPattern":null,"preventionTips":["Operators act on Vars — annotate accordingly"],"tags":["reflex","type-annotation","operator-dispatch"],"backgroundTag":"callback-signature-mismatch","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}