Example #1
0
    def _check_condition(self, node: ast.AST, cond: ast.AST) -> None:
        if isinstance(cond, ast.NameConstant) and cond.value is True:
            if isinstance(node, ast.While):
                return  # We should allow plain `while True:`

        real_node = operators.unwrap_unary_node(walrus.get_assigned_expr(cond))
        if isinstance(real_node, self._forbidden_nodes):
            self.add_violation(WrongKeywordConditionViolation(cond))
    def _check_condition(self, node: ast.AST, condition: ast.AST) -> None:
        real_node = operators.unwrap_unary_node(condition)
        if isinstance(real_node, ast.NameConstant) and real_node.value is True:
            if isinstance(node, ast.While):
                return  # We should allow `while True:`

        if isinstance(real_node, self._forbidden_nodes):
            self.add_violation(WrongKeywordConditionViolation(condition))
 def _check_condition(self, condition: ast.AST) -> None:
     with suppress(ValueError):
         constant = ast.literal_eval(condition)
         if not bool(constant):
             self.add_violation(
                 WrongKeywordConditionViolation(
                     condition,
                     text=str(constant) if constant != '' else '""',
                 ), )