(tokens, local_dict, global_dict)
return result
Inserts calls to ``Symbol`` for undefined variables.
Inserts calls to ``Symbol`` for undefined variables.
Inserts calls to Symbol for undefined variables .
def auto_symbol(tokens, local_dict, global_dict):
    """Inserts calls to ``Symbol`` for undefined variables."""
    result = []
    prevTok = (None, None)

    tokens.append((None, None))  # so zip traverses all tokens
    for tok, nextTok in zip(tokens, tokens[1:]):
        tokNum, tokVal = tok
        nextTokNum, nextTokVal = nextTok
        if tokNum == NAME:
            name = tokVal

            if (name in ['True', 'False', 'None']
                or iskeyword(name)
                or name in local_dict
                # Don't convert attribute access
                or (prevTok[0] == OP and prevTok[1] == '.')
                # Don't convert keyword arguments
                or (prevTok[0] == OP and prevTok[1] in ('(', ',')
                    and nextTokNum == OP and nextTokVal == '=')):
                result.append((NAME, name))
                continue
            elif name in global_dict:
                obj = global_dict[name]
                if isinstance(obj, (Basic, type)) or callable(obj):
                    result.append((NAME, name))
                    continue

            result.extend([
                (NAME, 'Symbol'),
                (OP, '('),
                (NAME, repr(str(name))),
                (OP, ')'),
            ])
        else:
            result.append((tokNum, tokVal))

        prevTok = (tokNum, tokVal)

    return result
def auto_symbol ( tokens , local_dict , global_dict ) : result = [ ] prevTok = ( None , None ) tokens . append ( ( None , None ) ) # so zip traverses all tokens for tok , nextTok in zip ( tokens , tokens [ 1 : ] ) : tokNum , tokVal = tok nextTokNum , nextTokVal = nextTok if tokNum == NAME : name = tokVal if ( name in [ 'True' , 'False' , 'None' ] or iskeyword ( name ) or name in local_dict # Don't convert attribute access or ( prevTok [ 0 ] == OP and prevTok [ 1 ] == '.' ) # Don't convert keyword arguments or ( prevTok [ 0 ] == OP and prevTok [ 1 ] in ( '(' , ',' ) and nextTokNum == OP and nextTokVal == '=' ) ) : result . append ( ( NAME , name ) ) continue elif name in global_dict : obj = global_dict [ name ] if isinstance ( obj , ( Basic , type ) ) or callable ( obj ) : result . append ( ( NAME , name ) ) continue result . extend ( [ ( NAME , 'Symbol' ) , ( OP , '(' ) , ( NAME , repr ( str ( name ) ) ) , ( OP , ')' ) , ] ) else : result . append ( ( tokNum , tokVal ) ) prevTok = ( tokNum , tokVal ) return result