{"record":{"id":"7457741310734c1f","repo":"huggingface/smolagents","slug":"super-needs-at-least-one-argument","errorCode":null,"errorMessage":"super() needs at least one argument","messagePattern":"super\\(\\) needs at least one argument","errorType":"exception","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":891,"sourceCode":"\n    kwargs = {}\n    for keyword in call.keywords:\n        if keyword.arg is None:\n            # **kwargs unpacking\n            starred_dict = evaluate_ast(keyword.value, state, static_tools, custom_tools, authorized_imports)\n            if not isinstance(starred_dict, dict):\n                raise InterpreterError(f\"Cannot unpack non-dict value in **kwargs: {type(starred_dict).__name__}\")\n            kwargs.update(starred_dict)\n        else:\n            # Normal keyword argument\n            kwargs[keyword.arg] = evaluate_ast(keyword.value, state, static_tools, custom_tools, authorized_imports)\n\n    if func_name == \"super\":\n        if not args:\n            if \"__class__\" in state and \"self\" in state:\n                return super(state[\"__class__\"], state[\"self\"])\n            else:\n                raise InterpreterError(\"super() needs at least one argument\")\n        cls = args[0]\n        if not isinstance(cls, type):\n            raise InterpreterError(\"super() argument 1 must be type\")\n        if len(args) == 1:\n            return super(cls)\n        elif len(args) == 2:\n            instance = args[1]\n            return super(cls, instance)\n        else:\n            raise InterpreterError(\"super() takes at most 2 arguments\")\n    elif func_name == \"print\":\n        state[\"_print_outputs\"] += \" \".join(map(str, args)) + \"\\n\"\n        return None\n    else:  # Assume it's a callable object\n        if (inspect.getmodule(func) == builtins) and inspect.isbuiltin(func) and (func not in static_tools.values()):\n            raise InterpreterError(\n                f\"Invoking a builtin function that has not been explicitly added as a tool is not allowed ({func_name}).\"\n            )","sourceCodeStart":873,"sourceCodeEnd":909,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L873-L909","documentation":"Bare super() with no arguments requires the interpreter to know the enclosing class (__class__) and the instance (self) from local state. Inside this sandboxed executor, that context is only available for methods defined via class definitions executed in the same interpreter run; otherwise super() with no args is rejected.","triggerScenarios":"Calling super() with zero arguments in a function outside a class body executed by the interpreter, or in a lambda/nested function where __class__/self are not in state.","commonSituations":"Agent-generated code uses new-style bare super() in a standalone function or static method; the class was defined outside the sandbox so state lacks '__class__' and 'self'.","solutions":["Use the two-argument form: super(ClassName, self)","Define the class inside the same executed script so the interpreter tracks __class__ and self","Move the subclass logic outside agent-generated code into a pre-authorized tool"],"exampleFix":"# before\nclass B(A):\n    def run(self):\n        return super().run()  # context missing\n# after\nclass B(A):\n    def run(self):\n        return super(B, self).run()","handlingStrategy":"validation","validationCode":"# in generated code: avoid bare super() unless inside a method of a class defined in the same block\nsuper(ClassName, self).method()","typeGuard":null,"tryCatchPattern":"try:\n    evaluate_python(code, ...)\nexcept InterpreterError as e:\n    if 'super()' in str(e):\n        code = code.replace('super()', f'super({cls_name}, self)'); evaluate_python(code, ...)","preventionTips":["Always use the two-argument super() form in sandboxed code","Define classes and their subclasses in the same executed script"],"tags":["python-executor","super","oop","smolagents"],"backgroundTag":"super-without-class-context","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}