code: def expand_function_ast_varargs(fn_ast, expand_number):
      """
      Given a function AST that use a variable length positional argument
      (e.g. *args), return a function that replaces the use of this argument
      with one or more fixed arguments.
  
      To be supported, a function must have a starred argument in the function
      signature, and it may only use this argument in starred form as the
      input to other functions.
  
      For example, suppose expand_number is 3 and fn_ast is an AST
      representing this function...
  
      def my_fn1(a, b, *args):
          print(a, b)
          other_fn(a, b, *args)
  
      Then this function will return the AST of a function equivalent to...
  
      def my_fn1(a, b, _0, _1, _2):
          print(a, b)
          other_fn(a, b, _0, _1, _2)
  
      If the input function uses `args` for anything other than passing it to
      other functions in starred form, an error will be raised.
  
      Parameters
      ----------
      fn_ast: ast.FunctionDef
      expand_number: int
  
      Returns
      -------
      ast.FunctionDef
      """
      assert isinstance(fn_ast, ast.Module)
  
      # Copy ast so we don't modify the input
      fn_ast = copy.deepcopy(fn_ast)
  
      # Extract function definition
      fndef_ast = fn_ast.body[0]
      assert isinstance(fndef_ast, ast.FunctionDef)
  
      # Get function args
      fn_args = fndef_ast.args
  
      # Function variable arity argument
      fn_vararg = fn_args.vararg
  
      # Require vararg
      if not fn_vararg:
          raise ValueError(
              """\
  Input function AST does not have a variable length positional argument
  (e.g. *args) in the function signature"""
          )
      assert fn_vararg
  
      # Get vararg name
      if isinstance(fn_vararg, str):
          vararg_name = fn_vararg
      else:
          vararg_name = fn_vararg.arg
  
      # Compute new unique names to use in place of the variable argument
      before_name_visitor = NameVisitor()
      before_name_visitor.visit(fn_ast)
      expand_names = before_name_visitor.get_new_names(expand_number)
  
      # Replace use of *args in function body
      expand_transformer = ExpandVarargTransformerStarred
  
      new_fn_ast = expand_transformer(vararg_name, expand_names).visit(
          fn_ast
      )
  
      new_fndef_ast = new_fn_ast.body[0]
  
      # Replace vararg with additional args in function signature
      new_fndef_ast.args.args.extend(
          [_build_arg(name=name) for name in expand_names]
      )
      new_fndef_ast.args.vararg = None
  
      # Run a new NameVistor an see if there were any other non-starred uses
      # of the variable length argument. If so, raise an exception
      after_name_visitor = NameVisitor()
      after_name_visitor.visit(new_fn_ast)
      if vararg_name in after_name_visitor.names:
          raise ValueError(
              """\
  The variable length positional argument {n} is used in an unsupported context
  """.format(
                  n=vararg_name
              )
          )
  
      # Remove decorators if present to avoid recursion
      fndef_ast.decorator_list = []
  
      # Add missing source code locations
      ast.fix_missing_locations(new_fn_ast)
  
      # Return result
      return new_fn_ast
  
imports: import re
  import copy
  import inspect
  import ast
  import textwrap
label_desc: Use image node_id 6 for calling a global function with example usage: expand_function_ast_varargs(fn_ast, expand_number) and returns: new_fn_ast