Esempio n. 1
0
    def _check_return_path(self, node: ast.Try) -> None:
        try_has, except_has, else_has, finally_has = _find_returing_nodes(
            node, self._bad_returning_nodes,
        )

        if finally_has and (try_has or except_has or else_has):
            self.add_violation(TryExceptMultipleReturnPathViolation(node))
        elif else_has and try_has:
            self.add_violation(TryExceptMultipleReturnPathViolation(node))
    def _check_return_path(self, node: ast.Try) -> None:
        try_has = any(is_contained(line, ast.Return) for line in node.body)
        except_has = any(
            is_contained(except_handler, ast.Return)
            for except_handler in node.handlers)
        else_has = any(is_contained(line, ast.Return) for line in node.orelse)
        finally_has = any(
            is_contained(line, ast.Return) for line in node.finalbody)

        if finally_has and (try_has or except_has):
            self.add_violation(TryExceptMultipleReturnPathViolation(node))
        if else_has and try_has:
            self.add_violation(TryExceptMultipleReturnPathViolation(node))