def _check_infinite_while_loop(self, node: AnyLoop) -> None: if not isinstance(node, ast.While): return real_node = operators.unwrap_unary_node(node.test) if isinstance(real_node, ast.NameConstant) and real_node.value is True: if not loops.has_break(node, break_nodes=self._breaks): self.add_violation(InfiniteWhileLoopViolation(node))
def _check_infinite_while_loop(self, node: AnyLoop) -> None: if not isinstance(node, ast.While): return if loops.has_break(node, break_nodes=self._can_break_loop): return with suppress(ValueError): evaled = ast.literal_eval(node.test) if not isinstance(evaled, ast.Name) and bool(evaled): self.add_violation(InfiniteWhileLoopViolation(node))
def _check_loop_needs_else(self, node: AnyLoop) -> None: if node.orelse and not loops.has_break(node, break_nodes=(ast.Break, )): self.add_violation(UselessLoopElseViolation(node))