def _gen_ipython_string(func, args, defaults, original_doc):
  """Provides auto-complete hint to ipython.

  If the first line in a docstring is fn(arg1=, arg2=) then they are added to
  auto-complete.  This cannot be called on an instance method.

  Args:
    func: The function that will be modified.
    args: The arguments that this function takes in order.
    defaults: The default arguments corresponding the last arguments.
    original_doc: Original docstring to assign after the magic string.
  Returns:
    The new doc string with the magic bit prepended.
  """
  magic_string = '%s(' % func.__name__

  if defaults:
    default_offset = len(args) - len(defaults)
  else:
    default_offset = len(args)
  for i, value in enumerate(args):
    if i >= default_offset:
      magic_string += '%s=%s, ' % (value, defaults[i - default_offset])
    else:
      magic_string += '%s, ' % value
  if args:
    magic_string = magic_string[:-2]
  magic_string += ')\n\n'
  if original_doc is not None:
    magic_string += original_doc
  return magic_string