{"record":{"id":"b1b115d4a0ed5fc9","repo":"huggingface/smolagents","slug":"augassign-not-supported-for-type-target-targets","errorCode":null,"errorMessage":"AugAssign not supported for {type(target)} targets.","messagePattern":"AugAssign not supported for (.+?) targets\\.","errorType":"error_code","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":660,"sourceCode":"    custom_tools: dict[str, Callable],\n    authorized_imports: list[str],\n) -> Any:\n    def get_current_value(target: ast.AST) -> Any:\n        if isinstance(target, ast.Name):\n            return state.get(target.id, 0)\n        elif isinstance(target, ast.Subscript):\n            obj = evaluate_ast(target.value, state, static_tools, custom_tools, authorized_imports)\n            key = evaluate_ast(target.slice, state, static_tools, custom_tools, authorized_imports)\n            return obj[key]\n        elif isinstance(target, ast.Attribute):\n            obj = evaluate_ast(target.value, state, static_tools, custom_tools, authorized_imports)\n            return getattr(obj, target.attr)\n        elif isinstance(target, ast.Tuple):\n            return tuple(get_current_value(elt) for elt in target.elts)\n        elif isinstance(target, ast.List):\n            return [get_current_value(elt) for elt in target.elts]\n        else:\n            raise InterpreterError(\"AugAssign not supported for {type(target)} targets.\")\n\n    current_value = get_current_value(expression.target)\n    value_to_add = evaluate_ast(expression.value, state, static_tools, custom_tools, authorized_imports)\n\n    if isinstance(expression.op, ast.Add):\n        if isinstance(current_value, list):\n            if not isinstance(value_to_add, list):\n                raise InterpreterError(f\"Cannot add non-list value {value_to_add} to a list.\")\n            current_value += value_to_add\n        else:\n            current_value += value_to_add\n    elif isinstance(expression.op, ast.Sub):\n        current_value -= value_to_add\n    elif isinstance(expression.op, ast.Mult):\n        current_value *= value_to_add\n    elif isinstance(expression.op, ast.Div):\n        current_value /= value_to_add\n    elif isinstance(expression.op, ast.Mod):","sourceCodeStart":642,"sourceCodeEnd":678,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L642-L678","documentation":"Augmented assignment (+=, -=, ...) in executed code supports Name, Attribute, Subscript, Tuple and List targets; any other target node raises InterpreterError. Note the message is a literal '{type(target)}' (missing f-prefix upstream), so the text never shows the actual type — a known cosmetic bug.","triggerScenarios":"An augmented assignment whose target is not one of the supported node kinds — e.g. `a.b.c[0][1] += 1` chains that produce starred or nested expressions, or programmatically built AST with exotic targets.","commonSituations":"Rare with normal source code; mostly hit when generated code uses unusual target forms or when ASTs are constructed manually; users also report confusion because the message lacks the type due to the missing f-string prefix.","solutions":["Rewrite the augmented assignment as a plain assignment: read the value, compute, then assign via set_value-supported target (e.g. `x = x + 1`)","Use a simple variable as the target and write back afterwards (tmp = obj.attr; tmp += 1; obj.attr = tmp)","Upgrade smolagents — newer releases fix the f-string message so the actual target type is shown"],"exampleFix":"# before\ncode = \"obj.items[0] += 1\"\n\n# after\ncode = \"obj.items[0] = obj.items[0] + 1\"","handlingStrategy":"validation","validationCode":"import ast\nSUPPORTED = (ast.Name, ast.Attribute, ast.Subscript, ast.Tuple, ast.List)\nfor node in ast.walk(ast.parse(code)):\n    if isinstance(node, ast.AugAssign) and not isinstance(node.target, SUPPORTED):\n        raise ValueError('unsupported AugAssign target; rewrite as plain assignment')","typeGuard":null,"tryCatchPattern":"from smolagents.local_python_executor import InterpreterError\ntry:\n    evaluate_python(code)\nexcept InterpreterError as e:\n    if 'AugAssign not supported' in str(e):\n        code = desugar_augassign(code)  # x += 1 -> x = x + 1","preventionTips":["Keep augmented-assignment targets simple (plain names or single attributes)","Desugar complex += into read-modify-write assignments in generated code","Upgrade smolagents so the error message at least names the offending type"],"tags":["smolagents","augmented-assignment","unsupported-operation","interpreter-error","f-string-bug"],"backgroundTag":"unsupported-language-construct","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}