示例#1
0
 def visit_binop(self, node, parent):
     """visit a BinOp node by returning a fresh instance of it"""
     newnode = nodes.BinOp(self._bin_op_classes[type(node.op)], node.lineno,
                           node.col_offset, parent)
     newnode.postinit(self.visit(node.left, newnode),
                      self.visit(node.right, newnode))
     return newnode
示例#2
0
    def visit_binop(self, node, parent, assign_ctx=None):
        """visit a BinOp node by returning a fresh instance of it"""
        if isinstance(node.left, _ast.BinOp) and self._manager.optimize_ast:
            # Optimize BinOp operations in order to remove
            # redundant recursion. For instance, if the
            # following code is parsed in order to obtain
            # its ast, then the rebuilder will fail with an
            # infinite recursion, the same will happen with the
            # inference engine as well. There's no need to hold
            # so many objects for the BinOp if they can be reduced
            # to something else (also, the optimization
            # might handle only Const binops, which isn't a big
            # problem for the correctness of the program).
            #
            # ("a" + "b" + # one thousand more + "c")
            optimized = self._peepholer.optimize_binop(node)
            if optimized:
                _lineno_parent(node, optimized, parent)
                return optimized

        newnode = new.BinOp()
        _lineno_parent(node, newnode, parent)
        newnode.left = self.visit(node.left, newnode, assign_ctx)
        newnode.right = self.visit(node.right, newnode, assign_ctx)
        newnode.op = _BIN_OP_CLASSES[node.op.__class__]
        return newnode
示例#3
0
 def visit_binop(self, node, parent):
     """visit a BinOp node by returning a fresh instance of it"""
     newnode = new.BinOp()
     _lineno_parent(node, newnode, parent)
     newnode.left = self.visit(node.left, newnode)
     newnode.right = self.visit(node.right, newnode)
     newnode.op = _BIN_OP_CLASSES[node.op.__class__]
     return newnode
示例#4
0
def binop_node(draw, left=None, op=non_boolean_operator, right=None):
    left = left or const_node()
    right = right or const_node()
    node = nodes.BinOp(draw(op))
    node.postinit(draw(left), draw(right))
    return node