huggingface/smolagents · error · InterpreterError

super() takes at most 2 arguments

Error message

super() takes at most 2 arguments

What it means

super() accepts at most two arguments (type, object-or-type). The sandboxed interpreter raises this when three or more positional arguments are given.

Source

Thrown at src/smolagents/local_python_executor.py:901

            # Normal keyword argument
            kwargs[keyword.arg] = evaluate_ast(keyword.value, state, static_tools, custom_tools, authorized_imports)

    if func_name == "super":
        if not args:
            if "__class__" in state and "self" in state:
                return super(state["__class__"], state["self"])
            else:
                raise InterpreterError("super() needs at least one argument")
        cls = args[0]
        if not isinstance(cls, type):
            raise InterpreterError("super() argument 1 must be type")
        if len(args) == 1:
            return super(cls)
        elif len(args) == 2:
            instance = args[1]
            return super(cls, instance)
        else:
            raise InterpreterError("super() takes at most 2 arguments")
    elif func_name == "print":
        state["_print_outputs"] += " ".join(map(str, args)) + "\n"
        return None
    else:  # Assume it's a callable object
        if (inspect.getmodule(func) == builtins) and inspect.isbuiltin(func) and (func not in static_tools.values()):
            raise InterpreterError(
                f"Invoking a builtin function that has not been explicitly added as a tool is not allowed ({func_name})."
            )
        if (
            hasattr(func, "__name__")
            and func.__name__.startswith("__")
            and func.__name__.endswith("__")
            and (func.__name__ not in static_tools)
            and (func.__name__ not in ALLOWED_DUNDER_METHODS)
        ):
            raise InterpreterError(f"Forbidden call to dunder function: {func.__name__}")
        return func(*args, **kwargs)

View on GitHub (pinned to 30bb116109)

Solutions

  1. Pass exactly one or two arguments to super()
  2. If using *args unpacking, slice to the first two elements: super(*args[:2])
  3. Review the call site for accidental extra positional args

Example fix

# before
super(*args)          # args has 3 items
# after
super(*args[:2])      # or super(args[0], args[1])
Defensive patterns

Strategy: validation

Validate before calling

assert 1 <= len(call_args) <= 2, f'super() takes 1-2 args, got {len(call_args)}'

Try / catch

try:
    evaluate_python(code, ...)
except InterpreterError as e:
    if 'at most 2 arguments' in str(e):
        # trim extra args and retry

Prevention

When it happens

Trigger: super(A, obj, extra) or f(*args) unpacking more than two arguments into super().

Common situations: Agent code unpacks a tuple with *args that happens to contain extra elements; misunderstanding of super()'s signature.

Related errors


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