コード例 #1
0
ファイル: fastparse2.py プロジェクト: smalias/mypy
    def try_handler(self,
                    body: List[ast27.stmt],
                    handlers: List[ast27.ExceptHandler],
                    orelse: List[ast27.stmt],
                    finalbody: List[ast27.stmt],
                    lineno: int) -> TryStmt:
        vs = []  # type: List[Optional[NameExpr]]
        for item in handlers:
            if item.name is None:
                vs.append(None)
            elif isinstance(item.name, ast27.Name):
                vs.append(NameExpr(item.name.id))
            else:
                self.fail("Sorry, `except <expr>, <anything but a name>` is not supported",
                          item.lineno, item.col_offset)
                vs.append(None)
        types = [self.visit(h.type) for h in handlers]
        handlers_ = [self.as_required_block(h.body, h.lineno) for h in handlers]

        return TryStmt(self.as_required_block(body, lineno),
                       vs,
                       types,
                       handlers_,
                       self.as_block(orelse, lineno),
                       self.as_block(finalbody, lineno))
コード例 #2
0
 def visit_try_stmt(self, node: TryStmt) -> TryStmt:
     return TryStmt(self.block(node.body),
                    self.optional_names(node.vars),
                    self.optional_expressions(node.types),
                    self.blocks(node.handlers),
                    self.optional_block(node.else_body),
                    self.optional_block(node.finally_body))
コード例 #3
0
ファイル: fastparse.py プロジェクト: tony/mypy
    def visit_Try(self, n: ast35.Try) -> Node:
        vs = [NameExpr(h.name) if h.name is not None else None for h in n.handlers]
        types = [self.visit(h.type) for h in n.handlers]
        handlers = [self.as_block(h.body, h.lineno) for h in n.handlers]

        return TryStmt(self.as_block(n.body, n.lineno),
                       vs,
                       types,
                       handlers,
                       self.as_block(n.orelse, n.lineno),
                       self.as_block(n.finalbody, n.lineno))
コード例 #4
0
    def visit_Try(self, n: ast3.Try) -> TryStmt:
        vs = [
            NameExpr(h.name) if h.name is not None else None
            for h in n.handlers
        ]
        types = [self.visit(h.type) for h in n.handlers]
        handlers = [
            self.as_required_block(h.body, h.lineno) for h in n.handlers
        ]

        node = TryStmt(self.as_required_block(n.body, n.lineno), vs, types,
                       handlers, self.as_block(n.orelse, n.lineno),
                       self.as_block(n.finalbody, n.lineno))
        return self.set_line(node, n)
コード例 #5
0
ファイル: fastparse2.py プロジェクト: wlmgithub/mypy
    def try_handler(self, body: List[ast27.stmt],
                    handlers: List[ast27.ExceptHandler],
                    orelse: List[ast27.stmt], finalbody: List[ast27.stmt],
                    lineno: int) -> TryStmt:
        def produce_name(item: ast27.ExceptHandler) -> Optional[NameExpr]:
            if item.name is None:
                return None
            elif isinstance(item.name, ast27.Name):
                return NameExpr(item.name.id)
            else:
                raise RuntimeError("'{}' has non-Name name.".format(
                    ast27.dump(item)))

        vs = [produce_name(h) for h in handlers]
        types = [self.visit(h.type) for h in handlers]
        handlers_ = [self.as_block(h.body, h.lineno) for h in handlers]

        return TryStmt(self.as_block(body, lineno), vs, types, handlers_,
                       self.as_block(orelse, lineno),
                       self.as_block(finalbody, lineno))