Method: pylint.checkers.variables.NamesConsumer.get_next_to_consume
Calls: 15897, Exceptions: 6, Paths: 13Back
Path 1: 8749 calls (0.55)
Name (8740) AssignName (7) DelName (2)
None (8749)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 2: 5880 calls (0.37)
Name (5789) AssignName (79) DelName (12)
list (5877) [] (3)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 3: 601 calls (0.04)
Name (601)
None (601)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 4: 333 calls (0.02)
Name (333)
list (333)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 5: 182 calls (0.01)
Name (182)
list (182)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 6: 97 calls (0.01)
Name (97)
list (97)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 7: 25 calls (0.0)
Name (25)
[] (25)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 8: 10 calls (0.0)
Name (10)
[] (10)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 9: 6 calls (0.0)
Name (3) AssignName (3)
list (6)
GeneratorExit (6)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 10: 5 calls (0.0)
Name (5)
None (5)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 11: 5 calls (0.0)
Name (5)
[] (5)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 12: 3 calls (0.0)
Name (3)
[] (3)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes
Path 13: 1 calls (0.0)
Name (1)
None (1)
1def get_next_to_consume(self, node: nodes.Name) -> list[nodes.NodeNG] | None:
2 """Return a list of the nodes that define `node` from this scope.
3
4 If it is uncertain whether a node will be consumed, such as for statements in
5 except blocks, add it to self.consumed_uncertain instead of returning it.
6 Return None to indicate a special case that needs to be handled by the caller.
7 """
8 name = node.name
9 parent_node = node.parent
10 found_nodes = self.to_consume.get(name)
11 node_statement = node.statement(future=True)
12 if (
13 found_nodes
14 and isinstance(parent_node, nodes.Assign)
15 and parent_node == found_nodes[0].parent
16 ):
17 lhs = found_nodes[0].parent.targets[0]
18 if lhs.name == name: # this name is defined in this very statement
19 found_nodes = None
20
21 if (
22 found_nodes
23 and isinstance(parent_node, nodes.For)
24 and parent_node.iter == node
25 and parent_node.target in found_nodes
26 ):
27 found_nodes = None
28
29 # Before filtering, check that this node's name is not a nonlocal
30 if any(
31 isinstance(child, nodes.Nonlocal) and node.name in child.names
32 for child in node.frame(future=True).get_children()
33 ):
34 return found_nodes
35
36 # And no comprehension is under the node's frame
37 if VariablesChecker._comprehension_between_frame_and_node(node):
38 return found_nodes
39
40 # Filter out assignments guarded by always false conditions
41 if found_nodes:
42 uncertain_nodes = self._uncertain_nodes_in_false_tests(found_nodes, node)
43 self.consumed_uncertain[node.name] += uncertain_nodes
44 uncertain_nodes_set = set(uncertain_nodes)
45 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
46
47 # Filter out assignments in ExceptHandlers that node is not contained in
48 if found_nodes:
49 found_nodes = [
50 n
51 for n in found_nodes
52 if not isinstance(n.statement(future=True), nodes.ExceptHandler)
53 or n.statement(future=True).parent_of(node)
54 ]
55
56 # Filter out assignments in an Except clause that the node is not
57 # contained in, assuming they may fail
58 if found_nodes:
59 uncertain_nodes = self._uncertain_nodes_in_except_blocks(
60 found_nodes, node, node_statement
61 )
62 self.consumed_uncertain[node.name] += uncertain_nodes
63 uncertain_nodes_set = set(uncertain_nodes)
64 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
65
66 # If this node is in a Finally block of a Try/Finally,
67 # filter out assignments in the try portion, assuming they may fail
68 if found_nodes:
69 uncertain_nodes = (
70 self._uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
71 found_nodes, node_statement
72 )
73 )
74 self.consumed_uncertain[node.name] += uncertain_nodes
75 uncertain_nodes_set = set(uncertain_nodes)
76 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
77
78 # If this node is in an ExceptHandler,
79 # filter out assignments in the try portion, assuming they may fail
80 if found_nodes:
81 uncertain_nodes = (
82 self._uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
83 found_nodes, node_statement
84 )
85 )
86 self.consumed_uncertain[node.name] += uncertain_nodes
87 uncertain_nodes_set = set(uncertain_nodes)
88 found_nodes = [n for n in found_nodes if n not in uncertain_nodes_set]
89
90 return found_nodes