Method: pylint.checkers.variables.VariablesChecker._ignore_class_scope
Calls: 1574, Exceptions: 0, Paths: 4Back
Path 1: 881 calls (0.56)
Name (879) AssignName (2)
True (881)
1def _ignore_class_scope(self, node: nodes.NodeNG) -> bool:
2 """Return True if the node is in a local class scope, as an assignment.
3
4 Detect if we are in a local class scope, as an assignment.
5 For example, the following is fair game.
6
7 class A:
8 b = 1
9 c = lambda b=b: b * b
10
11 class B:
12 tp = 1
13 def func(self, arg: tp):
14 ...
15 class C:
16 tp = 2
17 def func(self, arg=tp):
18 ...
19 class C:
20 class Tp:
21 pass
22 class D(Tp):
23 ...
24 """
25 name = node.name
26 frame = node.statement(future=True).scope()
27 in_annotation_or_default_or_decorator = self._defined_in_function_definition(
28 node, frame
29 )
30 in_ancestor_list = utils.is_ancestor_name(frame, node)
31 if in_annotation_or_default_or_decorator or in_ancestor_list:
32 frame_locals = frame.parent.scope().locals
33 else:
34 frame_locals = frame.locals
35 return not (
36 (isinstance(frame, nodes.ClassDef) or in_annotation_or_default_or_decorator)
37 and not self._in_lambda_or_comprehension_body(node, frame)
38 and name in frame_locals
39 )
Path 2: 665 calls (0.42)
Name (665)
True (613) False (52)
1def _ignore_class_scope(self, node: nodes.NodeNG) -> bool:
2 """Return True if the node is in a local class scope, as an assignment.
3
4 Detect if we are in a local class scope, as an assignment.
5 For example, the following is fair game.
6
7 class A:
8 b = 1
9 c = lambda b=b: b * b
10
11 class B:
12 tp = 1
13 def func(self, arg: tp):
14 ...
15 class C:
16 tp = 2
17 def func(self, arg=tp):
18 ...
19 class C:
20 class Tp:
21 pass
22 class D(Tp):
23 ...
24 """
25 name = node.name
26 frame = node.statement(future=True).scope()
27 in_annotation_or_default_or_decorator = self._defined_in_function_definition(
28 node, frame
29 )
30 in_ancestor_list = utils.is_ancestor_name(frame, node)
31 if in_annotation_or_default_or_decorator or in_ancestor_list:
32 frame_locals = frame.parent.scope().locals
33 else:
34 frame_locals = frame.locals
35 return not (
36 (isinstance(frame, nodes.ClassDef) or in_annotation_or_default_or_decorator)
37 and not self._in_lambda_or_comprehension_body(node, frame)
38 and name in frame_locals
39 )
Path 3: 18 calls (0.01)
Name (18)
True (18)
1def _ignore_class_scope(self, node: nodes.NodeNG) -> bool:
2 """Return True if the node is in a local class scope, as an assignment.
3
4 Detect if we are in a local class scope, as an assignment.
5 For example, the following is fair game.
6
7 class A:
8 b = 1
9 c = lambda b=b: b * b
10
11 class B:
12 tp = 1
13 def func(self, arg: tp):
14 ...
15 class C:
16 tp = 2
17 def func(self, arg=tp):
18 ...
19 class C:
20 class Tp:
21 pass
22 class D(Tp):
23 ...
24 """
25 name = node.name
26 frame = node.statement(future=True).scope()
27 in_annotation_or_default_or_decorator = self._defined_in_function_definition(
28 node, frame
29 )
30 in_ancestor_list = utils.is_ancestor_name(frame, node)
31 if in_annotation_or_default_or_decorator or in_ancestor_list:
32 frame_locals = frame.parent.scope().locals
33 else:
34 frame_locals = frame.locals
35 return not (
36 (isinstance(frame, nodes.ClassDef) or in_annotation_or_default_or_decorator)
37 and not self._in_lambda_or_comprehension_body(node, frame)
38 and name in frame_locals
39 )
Path 4: 10 calls (0.01)
Name (10)
True (6) False (4)
1def _ignore_class_scope(self, node: nodes.NodeNG) -> bool:
2 """Return True if the node is in a local class scope, as an assignment.
3
4 Detect if we are in a local class scope, as an assignment.
5 For example, the following is fair game.
6
7 class A:
8 b = 1
9 c = lambda b=b: b * b
10
11 class B:
12 tp = 1
13 def func(self, arg: tp):
14 ...
15 class C:
16 tp = 2
17 def func(self, arg=tp):
18 ...
19 class C:
20 class Tp:
21 pass
22 class D(Tp):
23 ...
24 """
25 name = node.name
26 frame = node.statement(future=True).scope()
27 in_annotation_or_default_or_decorator = self._defined_in_function_definition(
28 node, frame
29 )
30 in_ancestor_list = utils.is_ancestor_name(frame, node)
31 if in_annotation_or_default_or_decorator or in_ancestor_list:
32 frame_locals = frame.parent.scope().locals
33 else:
34 frame_locals = frame.locals
35 return not (
36 (isinstance(frame, nodes.ClassDef) or in_annotation_or_default_or_decorator)
37 and not self._in_lambda_or_comprehension_body(node, frame)
38 and name in frame_locals
39 )