{"record":{"id":"452eb89f25d1afb1","repo":"huggingface/smolagents","slug":"binary-operation-type-binop-op-name-is-not","errorCode":null,"errorMessage":"Binary operation {type(binop.op).__name__} is not implemented.","messagePattern":"Binary operation (.+?) is not implemented\\.","errorType":"error_code","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":767,"sourceCode":"        return left_val / right_val\n    elif isinstance(binop.op, ast.Mod):\n        return left_val % right_val\n    elif isinstance(binop.op, ast.Pow):\n        return left_val**right_val\n    elif isinstance(binop.op, ast.FloorDiv):\n        return left_val // right_val\n    elif isinstance(binop.op, ast.BitAnd):\n        return left_val & right_val\n    elif isinstance(binop.op, ast.BitOr):\n        return left_val | right_val\n    elif isinstance(binop.op, ast.BitXor):\n        return left_val ^ right_val\n    elif isinstance(binop.op, ast.LShift):\n        return left_val << right_val\n    elif isinstance(binop.op, ast.RShift):\n        return left_val >> right_val\n    else:\n        raise NotImplementedError(f\"Binary operation {type(binop.op).__name__} is not implemented.\")\n\n\ndef evaluate_assign(\n    assign: ast.Assign,\n    state: dict[str, Any],\n    static_tools: dict[str, Callable],\n    custom_tools: dict[str, Callable],\n    authorized_imports: list[str],\n) -> Any:\n    result = evaluate_ast(assign.value, state, static_tools, custom_tools, authorized_imports)\n    if len(assign.targets) == 1:\n        target = assign.targets[0]\n        set_value(target, result, state, static_tools, custom_tools, authorized_imports)\n    else:\n        expanded_values = []\n        for tgt in assign.targets:\n            if isinstance(tgt, ast.Starred):\n                expanded_values.extend(result)","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L749-L785","documentation":"evaluate_binop covers the standard arithmetic/bitwise binary operators; anything else raises NotImplementedError naming the op class (note: NotImplementedError, not InterpreterError). With stock CPython grammar this is defensive — the notable gap historically is MatMult (@) not being implemented, and BoolOp/compare ops go through other paths.","triggerScenarios":"Executed code uses a binary operator the executor lacks — most commonly the matrix-multiply operator `a @ b` (ast.MatMult) — or an AST is fed with an unhandled operator node.","commonSituations":"LLM writes numpy code with `A @ B` or `A @ vector`; users port linear-algebra snippets into the sandbox and hit NotImplementedError instead of the expected result.","solutions":["Replace `A @ B` with an explicit call: `numpy.matmul(A, B)` or `numpy.dot(A, B)` or `A.dot(B)`","Check the smolagents changelog/upgrade — newer versions may implement MatMult","Keep matrix math in explicitly called library functions rather than operator syntax"],"exampleFix":"# before\ncode = \"import numpy as np\\nfinal_answer(A @ B)\"\n\n# after\ncode = \"import numpy as np\\nfinal_answer(np.matmul(A, B))\"","handlingStrategy":"validation","validationCode":"import ast\nfor node in ast.walk(ast.parse(code)):\n    if isinstance(node, ast.BinOp) and isinstance(node.op, ast.MatMult):\n        raise ValueError('A @ B is not supported; use numpy.matmul(A, B) instead')","typeGuard":null,"tryCatchPattern":"from smolagents.local_python_executor import evaluate_python\ntry:\n    evaluate_python(code)\nexcept NotImplementedError as e:\n    if 'Binary operation' in str(e):\n        code = code.replace(' @ ', ' np.matmul(')  # best: rewrite source properly","preventionTips":["Prefer np.matmul/np.dot over the @ operator in generated snippets","Check release notes when using operator-heavy numpy code in the sandbox","Pin a smolagents version you have tested with your operator set"],"tags":["smolagents","binary-operator","matmul","not-implemented","sandbox"],"backgroundTag":"unsupported-language-construct","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}