예제 #1
0
    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))
예제 #2
0
 def _check_lambda_inside_loop(self, node: AnyLoop) -> None:
     for subnode in node.body:
         if is_contained(subnode, (ast.Lambda, )):
             self.add_violation(LambdaInsideLoopViolation(node))
예제 #3
0
 def _check_method_contents(self, node: types.AnyFunctionDef) -> None:
     if node.name == constants.INIT:
         if is_contained(node, self._not_appropriate_for_init):
             self.add_violation(YieldInsideInitViolation(node))