Method: pylint.checkers.classes.class_checker.ClassChecker._check_unused_private_attributes
Calls: 1519, Exceptions: 0, Paths: 19Back
Path 1: 1302 calls (0.86)
ClassDef (1302)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 2: 192 calls (0.13)
ClassDef (192)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 3: 5 calls (0.0)
ClassDef (5)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 4: 2 calls (0.0)
ClassDef (2)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 5: 2 calls (0.0)
ClassDef (2)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 6: 2 calls (0.0)
ClassDef (2)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 7: 2 calls (0.0)
ClassDef (2)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 8: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 9: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 10: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 11: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 12: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 13: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 14: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 15: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 16: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 17: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 18: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)
Path 19: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
2 for assign_attr in node.nodes_of_class(nodes.AssignAttr):
3 if not is_attr_private(assign_attr.attrname) or not isinstance(
4 assign_attr.expr, nodes.Name
5 ):
6 continue
7
8 # Logic for checking false positive when using __new__,
9 # Get the returned object names of the __new__ magic function
10 # Then check if the attribute was consumed in other instance methods
11 acceptable_obj_names: list[str] = ["self"]
12 scope = assign_attr.scope()
13 if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
14 acceptable_obj_names.extend(
15 [
16 return_node.value.name
17 for return_node in scope.nodes_of_class(nodes.Return)
18 if isinstance(return_node.value, nodes.Name)
19 ]
20 )
21
22 for attribute in node.nodes_of_class(nodes.Attribute):
23 if attribute.attrname != assign_attr.attrname:
24 continue
25
26 if not isinstance(attribute.expr, nodes.Name):
27 continue
28
29 if assign_attr.expr.name in {
30 "cls",
31 node.name,
32 } and attribute.expr.name in {"cls", "self", node.name}:
33 # If assigned to cls or class name, can be accessed by cls/self/class name
34 break
35
36 if (
37 assign_attr.expr.name in acceptable_obj_names
38 and attribute.expr.name == "self"
39 ):
40 # If assigned to self.attrib, can only be accessed by self
41 # Or if __new__ was used, the returned object names are acceptable
42 break
43
44 if assign_attr.expr.name == attribute.expr.name == node.name:
45 # Recognise attributes which are accessed via the class name
46 break
47
48 else:
49 args = (node.name, assign_attr.attrname)
50 self.add_message("unused-private-member", node=assign_attr, args=args)