{"record":{"id":"ad712c17a7682857","repo":"huggingface/smolagents","slug":"unsupported-annassign-target-in-class-body-type","errorCode":null,"errorMessage":"Unsupported AnnAssign target in class body: {type(target).__name__}","messagePattern":"Unsupported AnnAssign target in class body: (.+?)","errorType":"error_code","errorClass":"InterpreterError","httpStatus":null,"severity":"warning","filePath":"src/smolagents/local_python_executor.py","lineNumber":594,"sourceCode":"                class_dict.setdefault(\"__annotations__\", {})[target.id] = annotation\n                # Assign value if provided\n                if stmt.value:\n                    class_dict[target.id] = value\n            elif isinstance(target, ast.Attribute):\n                # Attribute annotation like \"obj.attr: int\"\n                obj = evaluate_ast(target.value, class_dict, static_tools, custom_tools, authorized_imports)\n                # If there's a value assignment, set the attribute\n                if stmt.value:\n                    setattr(obj, target.attr, value)\n            elif isinstance(target, ast.Subscript):\n                # Subscript annotation like \"dict[key]: int\"\n                container = evaluate_ast(target.value, class_dict, static_tools, custom_tools, authorized_imports)\n                index = evaluate_ast(target.slice, state, static_tools, custom_tools, authorized_imports)\n                # If there's a value assignment, set the item\n                if stmt.value:\n                    container[index] = value\n            else:\n                raise InterpreterError(f\"Unsupported AnnAssign target in class body: {type(target).__name__}\")\n        elif isinstance(stmt, ast.Assign):\n            value = evaluate_ast(stmt.value, state, static_tools, custom_tools, authorized_imports)\n            for target in stmt.targets:\n                if isinstance(target, ast.Name):\n                    class_dict[target.id] = value\n                elif isinstance(target, ast.Attribute):\n                    obj = evaluate_ast(target.value, class_dict, static_tools, custom_tools, authorized_imports)\n                    setattr(obj, target.attr, value)\n        elif isinstance(stmt, ast.Pass):\n            pass\n        elif (\n            isinstance(stmt, ast.Expr)\n            and stmt == class_def.body[0]\n            and isinstance(stmt.value, ast.Constant)\n            and isinstance(stmt.value.value, str)\n        ):\n            # Check if it is a docstring: first statement in class body which is a string literal expression\n            class_dict[\"__doc__\"] = stmt.value.value","sourceCodeStart":576,"sourceCodeEnd":612,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L576-L612","documentation":"When evaluating a class body, evaluate_class_def handles annotated assignments (AnnAssign) only to Names, Attributes and Subscripts; any other target node type triggers InterpreterError naming the unsupported target class. It is a defensive exhaustiveness check for exotic AST shapes.","triggerScenarios":"A class body contains an AnnAssign whose target is not Name/Attribute/Subscript (not producible by normal Python source since annotations only allow simple targets; only reachable by feeding hand-built AST).","commonSituations":"Programmatically constructed AST passed to evaluate_ast; version skew where grammar allows new AnnAssign targets; meta-programming that mutates the AST before execution.","solutions":["Use only simple annotated targets (plain names) in class bodies: `x: int = 0`","If building ASTs manually, ensure AnnAssign targets are ast.Name nodes","Simplify the class body or move exotic constructs outside executed code"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import ast\nfor node in ast.walk(ast.parse(code)):\n    if isinstance(node, ast.ClassDef):\n        for stmt in node.body:\n            if isinstance(stmt, ast.AnnAssign) and not isinstance(stmt.target, (ast.Name, ast.Attribute, ast.Subscript)):\n                raise ValueError('unsupported AnnAssign target in class body')","typeGuard":null,"tryCatchPattern":"from smolagents.local_python_executor import InterpreterError\ntry:\n    evaluate_python(code)\nexcept InterpreterError as e:\n    if 'Unsupported AnnAssign target' in str(e):\n        simplify_class_body(code)","preventionTips":["Use only simple annotated names in class bodies","Avoid feeding hand-built ASTs to the executor","Keep class bodies limited to attributes and methods"],"tags":["smolagents","class-definition","annassign","unsupported-operation","interpreter-error"],"backgroundTag":"unsupported-language-construct","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}