huggingface/smolagents · error · InterpreterError

AugAssign not supported for {type(target)} targets.

Error message

AugAssign not supported for {type(target)} targets.

What it means

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.

Source

Thrown at src/smolagents/local_python_executor.py:660

    custom_tools: dict[str, Callable],
    authorized_imports: list[str],
) -> Any:
    def get_current_value(target: ast.AST) -> Any:
        if isinstance(target, ast.Name):
            return state.get(target.id, 0)
        elif isinstance(target, ast.Subscript):
            obj = evaluate_ast(target.value, state, static_tools, custom_tools, authorized_imports)
            key = evaluate_ast(target.slice, state, static_tools, custom_tools, authorized_imports)
            return obj[key]
        elif isinstance(target, ast.Attribute):
            obj = evaluate_ast(target.value, state, static_tools, custom_tools, authorized_imports)
            return getattr(obj, target.attr)
        elif isinstance(target, ast.Tuple):
            return tuple(get_current_value(elt) for elt in target.elts)
        elif isinstance(target, ast.List):
            return [get_current_value(elt) for elt in target.elts]
        else:
            raise InterpreterError("AugAssign not supported for {type(target)} targets.")

    current_value = get_current_value(expression.target)
    value_to_add = evaluate_ast(expression.value, state, static_tools, custom_tools, authorized_imports)

    if isinstance(expression.op, ast.Add):
        if isinstance(current_value, list):
            if not isinstance(value_to_add, list):
                raise InterpreterError(f"Cannot add non-list value {value_to_add} to a list.")
            current_value += value_to_add
        else:
            current_value += value_to_add
    elif isinstance(expression.op, ast.Sub):
        current_value -= value_to_add
    elif isinstance(expression.op, ast.Mult):
        current_value *= value_to_add
    elif isinstance(expression.op, ast.Div):
        current_value /= value_to_add
    elif isinstance(expression.op, ast.Mod):

View on GitHub (pinned to 30bb116109)

Solutions

  1. Rewrite the augmented assignment as a plain assignment: read the value, compute, then assign via set_value-supported target (e.g. `x = x + 1`)
  2. Use a simple variable as the target and write back afterwards (tmp = obj.attr; tmp += 1; obj.attr = tmp)
  3. Upgrade smolagents — newer releases fix the f-string message so the actual target type is shown

Example fix

# before
code = "obj.items[0] += 1"

# after
code = "obj.items[0] = obj.items[0] + 1"
Defensive patterns

Strategy: validation

Validate before calling

import ast
SUPPORTED = (ast.Name, ast.Attribute, ast.Subscript, ast.Tuple, ast.List)
for node in ast.walk(ast.parse(code)):
    if isinstance(node, ast.AugAssign) and not isinstance(node.target, SUPPORTED):
        raise ValueError('unsupported AugAssign target; rewrite as plain assignment')

Try / catch

from smolagents.local_python_executor import InterpreterError
try:
    evaluate_python(code)
except InterpreterError as e:
    if 'AugAssign not supported' in str(e):
        code = desugar_augassign(code)  # x += 1 -> x = x + 1

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/b1b115d4a0ed5fc9. Report an issue: GitHub.