Method: pylint.checkers.classes.class_checker.ClassChecker._check_classmethod_declaration
Calls: 3697, Exceptions: 15, Paths: 9Back
Path 1: 2937 calls (0.79)
Assign (2937)
None (2937)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 2: 738 calls (0.2)
Assign (738)
None (738)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 3: 9 calls (0.0)
Assign (9)
GeneratorExit (9)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 4: 6 calls (0.0)
Assign (6)
GeneratorExit (6)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 5: 3 calls (0.0)
Assign (3)
None (3)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 6: 1 calls (0.0)
Assign (1)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 7: 1 calls (0.0)
Assign (1)
None (1)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 8: 1 calls (0.0)
Assign (1)
None (1)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])
Path 9: 1 calls (0.0)
Assign (1)
None (1)
1def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
2 """Checks for uses of classmethod() or staticmethod().
3
4 When a @classmethod or @staticmethod decorator should be used instead.
5 A message will be emitted only if the assignment is at a class scope
6 and only if the classmethod's argument belongs to the class where it
7 is defined.
8 `node` is an assign node.
9 """
10 if not isinstance(node.value, nodes.Call):
11 return
12
13 # check the function called is "classmethod" or "staticmethod"
14 func = node.value.func
15 if not isinstance(func, nodes.Name) or func.name not in (
16 "classmethod",
17 "staticmethod",
18 ):
19 return
20
21 msg = (
22 "no-classmethod-decorator"
23 if func.name == "classmethod"
24 else "no-staticmethod-decorator"
25 )
26 # assignment must be at a class scope
27 parent_class = node.scope()
28 if not isinstance(parent_class, nodes.ClassDef):
29 return
30
31 # Check if the arg passed to classmethod is a class member
32 classmeth_arg = node.value.args[0]
33 if not isinstance(classmeth_arg, nodes.Name):
34 return
35
36 method_name = classmeth_arg.name
37 if any(method_name == member.name for member in parent_class.mymethods()):
38 self.add_message(msg, node=node.targets[0])