parameters: (func, reverse_index)
return_statement: return args_list
docstring: Given a function, returns a list of strings representing its args.
  
    This function produces a list of strings representing the arguments to a
    python function. It uses tf_inspect.getargspec, which
    does not generalize well to Python 3.x, which is more flexible in how *args
    and **kwargs are handled. This is not a problem in TF, since we have to remain
    compatible to Python 2.7 anyway.
  
    This function uses `__name__` for callables if it is available. This can lead
    to poor results for functools.partial and other callable objects.
  
    The returned string is Python code, so if it is included in a Markdown
    document, it should be typeset as code (using backticks), or escaped.
  
    Args:
      func: A function, method, or functools.partial to extract the signature for.
      reverse_index: A map from object ids to canonical full names to use.
  
    Returns:
      A list of strings representing the argument signature of `func` as python
      code.
docstring_summary: Given a function, returns a list of strings representing its args.
docstring_tokens: Given a function returns a list of strings representing its args .
function: def _generate_signature(func, reverse_index):
    """Given a function, returns a list of strings representing its args.
  
    This function produces a list of strings representing the arguments to a
    python function. It uses tf_inspect.getargspec, which
    does not generalize well to Python 3.x, which is more flexible in how *args
    and **kwargs are handled. This is not a problem in TF, since we have to remain
    compatible to Python 2.7 anyway.
  
    This function uses `__name__` for callables if it is available. This can lead
    to poor results for functools.partial and other callable objects.
  
    The returned string is Python code, so if it is included in a Markdown
    document, it should be typeset as code (using backticks), or escaped.
  
    Args:
      func: A function, method, or functools.partial to extract the signature for.
      reverse_index: A map from object ids to canonical full names to use.
  
    Returns:
      A list of strings representing the argument signature of `func` as python
      code.
    """
  
    args_list = []
  
    argspec = _get_arg_spec(func)
    first_arg_with_default = (
        len(argspec.args or []) - len(argspec.defaults or []))
  
    # Python documentation skips `self` when printing method signatures.
    # Note we cannot test for ismethod here since unbound methods do not register
    # as methods (in Python 3).
    first_arg = 1 if 'self' in argspec.args[:1] else 0
  
    # Add all args without defaults.
    for arg in argspec.args[first_arg:first_arg_with_default]:
      args_list.append(arg)
  
    # Add all args with defaults.
    if argspec.defaults:
      try:
        source = _remove_first_line_indent(tf_inspect.getsource(func))
        func_ast = ast.parse(source)
        ast_defaults = func_ast.body[0].args.defaults
      except IOError:  # If this is a builtin, getsource fails with IOError
        # If we cannot get the source, assume the AST would be equal to the repr
        # of the defaults.
        ast_defaults = [None] * len(argspec.defaults)
  
      for arg, default, ast_default in zip(
          argspec.args[first_arg_with_default:], argspec.defaults, ast_defaults):
        if id(default) in reverse_index:
          default_text = reverse_index[id(default)]
        elif ast_default is not None:
          default_text = codegen.to_source(ast_default)
          if default_text != repr(default):
            # This may be an internal name. If so, handle the ones we know about.
            # TODO(wicke): This should be replaced with a lookup in the index.
            # TODO(wicke): (replace first ident with tf., check if in index)
            internal_names = {
                'ops.GraphKeys': 'tf.GraphKeys',
                '_ops.GraphKeys': 'tf.GraphKeys',
                'init_ops.zeros_initializer': 'tf.zeros_initializer',
                'init_ops.ones_initializer': 'tf.ones_initializer',
                'saver_pb2.SaverDef': 'tf.train.SaverDef',
            }
            full_name_re = '^%s(.%s)+' % (IDENTIFIER_RE, IDENTIFIER_RE)
            match = re.match(full_name_re, default_text)
            if match:
              lookup_text = default_text
              for internal_name, public_name in six.iteritems(internal_names):
                if match.group(0).startswith(internal_name):
                  lookup_text = public_name + default_text[len(internal_name):]
                  break
              if default_text is lookup_text:
                print('WARNING: Using default arg, failed lookup: %s, repr: %r' %
                      (default_text, default))
              else:
                default_text = lookup_text
        else:
          default_text = repr(default)
  
        args_list.append('%s=%s' % (arg, default_text))
  
    # Add *args and *kwargs.
    if argspec.varargs:
      args_list.append('*' + argspec.varargs)
    if argspec.keywords:
      args_list.append('**' + argspec.keywords)
  
    return args_list
function_tokens: def _generate_signature ( func , reverse_index ) : args_list = [ ] argspec = _get_arg_spec ( func ) first_arg_with_default = ( len ( argspec . args or [ ] ) - len ( argspec . defaults or [ ] ) ) # Python documentation skips `self` when printing method signatures. # Note we cannot test for ismethod here since unbound methods do not register # as methods (in Python 3). first_arg = 1 if 'self' in argspec . args [ : 1 ] else 0 # Add all args without defaults. for arg in argspec . args [ first_arg : first_arg_with_default ] : args_list . append ( arg ) # Add all args with defaults. if argspec . defaults : try : source = _remove_first_line_indent ( tf_inspect . getsource ( func ) ) func_ast = ast . parse ( source ) ast_defaults = func_ast . body [ 0 ] . args . defaults except IOError : # If this is a builtin, getsource fails with IOError # If we cannot get the source, assume the AST would be equal to the repr # of the defaults. ast_defaults = [ None ] * len ( argspec . defaults ) for arg , default , ast_default in zip ( argspec . args [ first_arg_with_default : ] , argspec . defaults , ast_defaults ) : if id ( default ) in reverse_index : default_text = reverse_index [ id ( default ) ] elif ast_default is not None : default_text = codegen . to_source ( ast_default ) if default_text != repr ( default ) : # This may be an internal name. If so, handle the ones we know about. # TODO(wicke): This should be replaced with a lookup in the index. # TODO(wicke): (replace first ident with tf., check if in index) internal_names = { 'ops.GraphKeys' : 'tf.GraphKeys' , '_ops.GraphKeys' : 'tf.GraphKeys' , 'init_ops.zeros_initializer' : 'tf.zeros_initializer' , 'init_ops.ones_initializer' : 'tf.ones_initializer' , 'saver_pb2.SaverDef' : 'tf.train.SaverDef' , } full_name_re = '^%s(.%s)+' % ( IDENTIFIER_RE , IDENTIFIER_RE ) match = re . match ( full_name_re , default_text ) if match : lookup_text = default_text for internal_name , public_name in six . iteritems ( internal_names ) : if match . group ( 0 ) . startswith ( internal_name ) : lookup_text = public_name + default_text [ len ( internal_name ) : ] break if default_text is lookup_text : print ( 'WARNING: Using default arg, failed lookup: %s, repr: %r' % ( default_text , default ) ) else : default_text = lookup_text else : default_text = repr ( default ) args_list . append ( '%s=%s' % ( arg , default_text ) ) # Add *args and *kwargs. if argspec . varargs : args_list . append ( '*' + argspec . varargs ) if argspec . keywords : args_list . append ( '**' + argspec . keywords ) return args_list