예제 #1
0
    def visit_Raise(self, node):
        ntype = self._visit(node.type)
        ninst = self._visit(node.inst)
        ntback = self._visit(node.tback)

        what = ntype

        if ninst is not None:
            what = gast.Call(ntype, [ninst], [])
            gast.copy_location(what, node)
            what.end_lineno = what.end_col_offset = None

        if ntback is not None:
            attr = gast.Attribute(what, 'with_traceback', gast.Load())
            gast.copy_location(attr, node)
            attr.end_lineno = attr.end_col_offset = None

            what = gast.Call(attr, [ntback], [])
            gast.copy_location(what, node)
            what.end_lineno = what.end_col_offset = None

        new_node = gast.Raise(what, None)

        gast.copy_location(new_node, node)
        new_node.end_lineno = new_node.end_col_offset = None
        return new_node
예제 #2
0
    def visit_Raise(self, node):
        ntype = self._visit(node.type)
        ninst = self._visit(node.inst)
        ntback = self._visit(node.tback)

        what = ntype

        if ninst is not None:
            what = gast.Call(ntype, [ninst], [])
            ast.copy_location(what, node)

        if ntback is not None:
            attr = gast.Attribute(what, 'with_traceback', gast.Load())
            ast.copy_location(attr, node)

            what = gast.Call(
                attr,
                [ntback],
                []
            )
            ast.copy_location(what, node)

        new_node = gast.Raise(what, None)

        ast.copy_location(new_node, node)
        return new_node
예제 #3
0
 def visit_Try(self, node):
     if node.orelse:
         node.body.append(
             ast.Try(node.orelse,
                     [ast.ExceptHandler(None, None, [ast.Pass()])], [], []))
         node.orelse = []
         self.update = True
     if node.finalbody:
         node.body.extend(node.finalbody)
         node.finalbody.append(ast.Raise(None, None))
         self.update = True
         node = ast.Try(node.body,
                        [ast.ExceptHandler(None, None, node.finalbody)], [],
                        [])
         node.finalbody = []
     return node