Method: pylint.checkers.base.basic_error_checker._loop_exits_early
Calls: 38, Exceptions: 27, Paths: 1Back
Path 1: 38 calls (1.0)
For (27) While (11)
True (27) False (11)
GeneratorExit (27)
1def _loop_exits_early(loop: nodes.For | nodes.While) -> bool:
2 """Returns true if a loop may end with a break statement.
3
4 Args:
5 loop (astroid.For, astroid.While): the loop node inspected.
6
7 Returns:
8 bool: True if the loop may end with a break statement, False otherwise.
9 """
10 loop_nodes = (nodes.For, nodes.While)
11 definition_nodes = (nodes.FunctionDef, nodes.ClassDef)
12 inner_loop_nodes: list[nodes.For | nodes.While] = [
13 _node
14 for _node in loop.nodes_of_class(loop_nodes, skip_klass=definition_nodes)
15 if _node != loop
16 ]
17 return any(
18 _node
19 for _node in loop.nodes_of_class(nodes.Break, skip_klass=definition_nodes)
20 if _get_break_loop_node(_node) not in inner_loop_nodes
21 )