Method: pylint.checkers.classes.class_checker.ClassChecker._check_unused_private_functions
Calls: 1519, Exceptions: 1, Paths: 11Back
Path 1: 920 calls (0.61)
ClassDef (920)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 2: 585 calls (0.39)
ClassDef (585)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 3: 3 calls (0.0)
ClassDef (3)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 4: 2 calls (0.0)
ClassDef (2)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 5: 2 calls (0.0)
ClassDef (2)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 6: 2 calls (0.0)
ClassDef (2)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 7: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 8: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 9: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 10: 1 calls (0.0)
ClassDef (1)
GeneratorExit (1)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )
Path 11: 1 calls (0.0)
ClassDef (1)
1def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
2 for function_def in node.nodes_of_class(nodes.FunctionDef):
3 if not is_attr_private(function_def.name):
4 continue
5 parent_scope = function_def.parent.scope()
6 if isinstance(parent_scope, nodes.FunctionDef):
7 # Handle nested functions
8 if function_def.name in (
9 n.name for n in parent_scope.nodes_of_class(nodes.Name)
10 ):
11 continue
12 for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
13 # Check for cases where the functions are used as a variable instead of as a method call
14 if isinstance(child, nodes.Name) and child.name == function_def.name:
15 break
16 if isinstance(child, nodes.Attribute):
17 # Ignore recursive calls
18 if (
19 child.attrname != function_def.name
20 or child.scope() == function_def
21 ):
22 continue
23
24 # Check self.__attrname, cls.__attrname, node_name.__attrname
25 if isinstance(child.expr, nodes.Name) and child.expr.name in {
26 "self",
27 "cls",
28 node.name,
29 }:
30 break
31
32 # Check type(self).__attrname
33 if isinstance(child.expr, nodes.Call):
34 inferred = safe_infer(child.expr)
35 if (
36 isinstance(inferred, nodes.ClassDef)
37 and inferred.name == node.name
38 ):
39 break
40 else:
41 name_stack = []
42 curr = parent_scope
43 # Generate proper names for nested functions
44 while curr != node:
45 name_stack.append(curr.name)
46 curr = curr.parent.scope()
47
48 outer_level_names = f"{'.'.join(reversed(name_stack))}"
49 function_repr = f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})"
50 self.add_message(
51 "unused-private-member",
52 node=function_def,
53 args=(node.name, function_repr.lstrip(".")),
54 )