{"record":{"id":"deb43e5f584f85a2","repo":"reflex-dev/reflex","slug":"unsupported-operand-type-s-for-operator","errorCode":null,"errorMessage":"Unsupported Operand type(s) for {operator}: {', '.join(t.__name__ for t in operands_types)}","messagePattern":"Unsupported Operand type\\(s\\) for (.+?): (.+?)","errorType":"exception","errorClass":"VarTypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/number.py","lineNumber":56,"sourceCode":"\nif TYPE_CHECKING:\n    from .sequence import ArrayVar\n\n\ndef raise_unsupported_operand_types(\n    operator: str, operands_types: tuple[type, ...]\n) -> NoReturn:\n    \"\"\"Raise an unsupported operand types error.\n\n    Args:\n        operator: The operator.\n        operands_types: The types of the operands.\n\n    Raises:\n        VarTypeError: The operand types are unsupported.\n    \"\"\"\n    msg = f\"Unsupported Operand type(s) for {operator}: {', '.join(t.__name__ for t in operands_types)}\"\n    raise VarTypeError(msg)\n\n\nclass NumberVar(Var[NUMBER_T], python_types=(int, float, decimal.Decimal)):\n    \"\"\"Base class for immutable number vars.\"\"\"\n\n    def __add__(self, other: number_types) -> NumberVar:\n        \"\"\"Add two numbers.\n\n        Args:\n            other: The other number.\n\n        Returns:\n            The number addition operation.\n        \"\"\"\n        if not isinstance(other, NUMBER_TYPES):\n            raise_unsupported_operand_types(\"+\", (type(self), type(other)))\n        return number_add_operation(self, +other)\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/number.py#L38-L74","documentation":"NumberVar arithmetic operators (__add__, __sub__, __mul__ and their reflected variants) are typed to accept only number types (int, float, decimal.Decimal vars). At the type level, unsupported operand types trigger this VarTypeError via raise_unsupported_operand_types, mirroring TypeError from Python arithmetic.","triggerScenarios":"Adding/subtracting/multiplying a NumberVar by an operand whose static type is not int/float/Decimal — e.g. a StringVar, a boolean var, None, or an untyped Any that a type checker or runtime check rejects.","commonSituations":"Concatenating a number var with a string var using +; multiplying by a value from untyped JSON; pyright/mypy flagging the operation before runtime; version upgrades that tightened operand type annotations.","solutions":["Convert the other operand to a number var first (e.g. `rx.to_number_var(x)` / int()/float() on the literal).","For string building, use f-string or .concat()/str conversion instead of + on numbers.","Annotate the operand correctly so a plain Python number is passed rather than a non-number Var."],"exampleFix":"# before\ncount: rx.Var[int]\nlabel = count + \" items\"  # unsupported operand\n\n# after\nlabel = f\"{count} items\"","handlingStrategy":"type-guard","validationCode":"from reflex.vars import NumberVar\n\ndef is_number_operand(v) -> bool:\n    return isinstance(v, (int, float, decimal.Decimal)) or isinstance(v, NumberVar)","typeGuard":"import decimal\nfrom reflex.vars import NumberVar\n\ndef is_number_var_or_literal(v) -> bool:\n    return isinstance(v, NumberVar) or isinstance(v, (int, float, decimal.Decimal))","tryCatchPattern":null,"preventionTips":["Convert foreign vars with to_number/float conversions before arithmetic.","Use f-strings for combining numbers with strings.","Run pyright on component code to catch operand type issues statically."],"tags":["reflex","numbervar","type-error","arithmetic"],"backgroundTag":"var-unsupported-operand-types","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}