Method: pylint.checkers.variables.VariablesChecker._undefined_and_used_before_checker
Calls: 16687, Exceptions: 2, Paths: 18Back
Path 1: 5234 calls (0.31)
Name (5147) AssignName (77) DelName (10)
Expr (1529) Assign (1334) Return (1076) If (635) For (184) AugAssign (119) AnnAssign (99) With (76) Raise (75) Assert (64)
None (5234)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 2: 3750 calls (0.22)
Name (3599) AssignName (150) DelName (1)
Expr (1317) Assign (1062) If (536) AugAssign (223) Return (207) AnnAssign (114) For (107) Assert (54) With (52) Delete (24)
None (3750)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 3: 3461 calls (0.21)
Name (3461)
Expr (1378) AnnAssign (577) Assign (511) ExceptHandler (339) For (230) Raise (177) If (100) With (64) Return (44) Assert (34)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 4: 1372 calls (0.08)
Name (1372)
FunctionDef (629) Expr (312) ClassDef (164) Return (129) Raise (52) Assign (41) For (15) If (10) ExceptHandler (10) AnnAssign (3)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 5: 681 calls (0.04)
Name (678) AssignName (2) DelName (1)
Assign (229) Expr (201) With (64) AnnAssign (57) Return (56) ClassDef (25) If (15) While (7) For (6) Raise (6)
None (681)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 6: 610 calls (0.04)
Name (610)
ClassDef (337) FunctionDef (258) Return (7) AsyncFunctionDef (3) Assign (3) Expr (2)
None (610)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 7: 548 calls (0.03)
Name (548)
Assign (169) Expr (142) Return (66) ClassDef (64) AnnAssign (45) Raise (17) If (12) AsyncWith (11) With (10) For (4)
None (548)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 8: 424 calls (0.03)
Name (424)
FunctionDef (253) ClassDef (169) AsyncFunctionDef (2)
None (424)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 9: 198 calls (0.01)
Name (198)
Expr (86) Return (52) Assign (43) FunctionDef (10) AnnAssign (4) AsyncFunctionDef (1) If (1) ClassDef (1)
None (198)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 10: 194 calls (0.01)
Name (194)
Expr (72) Assign (35) If (30) Raise (19) With (16) Return (11) ExceptHandler (4) Assert (3) For (2) AugAssign (2)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 11: 112 calls (0.01)
Name (112)
Assign (33) Return (30) Expr (23) FunctionDef (13) ClassDef (6) AnnAssign (5) AugAssign (1) If (1)
None (112)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 12: 53 calls (0.0)
Name (53)
FunctionDef (29) Assign (16) Return (4) ClassDef (4)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 13: 41 calls (0.0)
Name (39) AssignName (2)
Assign (26) If (6) With (5) Expr (2) AugAssign (2)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 14: 3 calls (0.0)
DelName (2) AssignName (1)
Delete (2) AugAssign (1)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 15: 2 calls (0.0)
Name (2)
Return (2)
GeneratorExit (2)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 16: 2 calls (0.0)
AssignName (2)
AugAssign (2)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 17: 1 calls (0.0)
Name (1)
If (1)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)
Path 18: 1 calls (0.0)
Name (1)
Expr (1)
1def _undefined_and_used_before_checker(
2 self, node: nodes.Name, stmt: nodes.NodeNG
3 ) -> None:
4 frame = stmt.scope()
5 start_index = len(self._to_consume) - 1
6
7 # iterates through parent scopes, from the inner to the outer
8 base_scope_type = self._to_consume[start_index].scope_type
9
10 for i in range(start_index, -1, -1):
11 current_consumer = self._to_consume[i]
12
13 # Certain nodes shouldn't be checked as they get checked another time
14 if self._should_node_be_skipped(node, current_consumer, i == start_index):
15 continue
16
17 action, nodes_to_consume = self._check_consumer(
18 node, stmt, frame, current_consumer, base_scope_type
19 )
20 if nodes_to_consume:
21 # Any nodes added to consumed_uncertain by get_next_to_consume()
22 # should be added back so that they are marked as used.
23 # They will have already had a chance to emit used-before-assignment.
24 # We check here instead of before every single return in _check_consumer()
25 nodes_to_consume += current_consumer.consumed_uncertain[node.name]
26 current_consumer.mark_as_consumed(node.name, nodes_to_consume)
27 if action is VariableVisitConsumerAction.CONTINUE:
28 continue
29 if action is VariableVisitConsumerAction.RETURN:
30 return
31
32 # we have not found the name, if it isn't a builtin, that's an
33 # undefined name !
34 if not (
35 node.name in nodes.Module.scope_attrs
36 or utils.is_builtin(node.name)
37 or node.name in self.linter.config.additional_builtins
38 or (
39 node.name == "__class__"
40 and any(
41 i.is_method()
42 for i in node.node_ancestors()
43 if isinstance(i, nodes.FunctionDef)
44 )
45 )
46 ) and not utils.node_ignores_exception(node, NameError):
47 self.add_message("undefined-variable", args=node.name, node=node)