示例#1
0
 def _do_TupleExpression(self, node, context):
     if context == OP_APPLY:
         nodes = map(self.transform, node.Items)
         return ast.Tuple(nodes)
     else:
         transform = lambda node: self.transform(node, context)
         nodes = map(transform, node.Items)
         return ast.AssTuple(nodes)
示例#2
0
def p_testlist(p):
    """testlist : testlist_multi COMMA
                | testlist_multi """
    if len(p) == 2:
        p[0] = p[1]
    else:
        # May need to promote singleton to tuple
        if isinstance(p[1], list):
            p[0] = p[1]
        else:
            p[0] = [p[1]]
    # Convert into a tuple?
    if isinstance(p[0], list):
        p[0] = ast.Tuple(p[0])
示例#3
0
 def comma(self, *elems):
     ","
     for e in elems: assertResult(e, "use in tuple")
     return ast.Tuple(map(topy, elems))
示例#4
0
 def tuple(obj):
     for x in obj: assertResult(x, 'use in tuple')
     return ast.Tuple(map(topy, obj))
示例#5
0
 def paren(self, expr):
     "("
     if expr == None:
         return ast.Tuple()
     return topy(expr)
示例#6
0
def compileTuple(doc):
    for x in doc:
        assertResult(x, "use in tuple")
    return ast.Tuple([topy(x) for x in doc])
示例#7
0
 def BUILD_TUPLE(decompiler, size):
     return ast.Tuple(decompiler.pop_items(size))
示例#8
0
 def visitSubscript(self, node):
     return ast.CallFunc(ast.Name('_lookup_item'), [
         ast.Name('data'),
         self.visit(node.expr),
         ast.Tuple([self.visit(sub) for sub in node.subs])
     ])