Path 1: 5235 calls (0.45)

Name (5073) AssignName (159) DelName (3)

None (5235)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 2: 4509 calls (0.39)

Name (4426) AssignName (73) DelName (10)

None (4509)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 3: 1577 calls (0.14)

Name (1575) DelName (1) AssignName (1)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 4: 81 calls (0.01)

Name (80) AssignName (1)

None (81)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 5: 63 calls (0.01)

Name (63)

None (63)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 6: 33 calls (0.0)

Name (33)

None (33)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 7: 17 calls (0.0)

Name (17)

None (17)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 8: 11 calls (0.0)

Name (11)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 9: 7 calls (0.0)

Name (7)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 10: 2 calls (0.0)

Name (2)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 11: 1 calls (0.0)

Name (1)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 12: 1 calls (0.0)

Name (1)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)
            

Path 13: 1 calls (0.0)

Name (1)

1def _check_late_binding_closure(self, node: nodes.Name) -> None:
2        """Check whether node is a cell var that is assigned within a containing loop.
3
4        Special cases where we don't care about the error:
5        1. When the node's function is immediately called, e.g. (lambda: i)()
6        2. When the node's function is returned from within the loop, e.g. return lambda: i
7        """
8        if not self.linter.is_message_enabled("cell-var-from-loop"):
9            return
10
11        node_scope = node.frame(future=True)
12
13        # If node appears in a default argument expression,
14        # look at the next enclosing frame instead
15        if utils.is_default_argument(node, node_scope):
16            node_scope = node_scope.parent.frame(future=True)
17
18        # Check if node is a cell var
19        if (
20            not isinstance(node_scope, (nodes.Lambda, nodes.FunctionDef))
21            or node.name in node_scope.locals
22        ):
23            return
24
25        assign_scope, stmts = node.lookup(node.name)
26        if not stmts or not assign_scope.parent_of(node_scope):
27            return
28
29        if utils.is_comprehension(assign_scope):
30            self.add_message("cell-var-from-loop", node=node, args=node.name)
31        else:
32            # Look for an enclosing For loop.
33            # Currently, we only consider the first assignment
34            assignment_node = stmts[0]
35
36            maybe_for = assignment_node
37            while maybe_for and not isinstance(maybe_for, nodes.For):
38                if maybe_for is assign_scope:
39                    break
40                maybe_for = maybe_for.parent
41            else:
42                if (
43                    maybe_for
44                    and maybe_for.parent_of(node_scope)
45                    and not utils.is_being_called(node_scope)
46                    and node_scope.parent
47                    and not isinstance(node_scope.statement(future=True), nodes.Return)
48                ):
49                    self.add_message("cell-var-from-loop", node=node, args=node.name)