Method: pylint.checkers.classes.class_checker.ClassChecker._check_signature
Calls: 260, Exceptions: 0, Paths: 12Back
Path 1: 126 calls (0.48)
FunctionDef (123) AsyncFunctionDef (3)
FunctionDef (123) AsyncFunctionDef (3)
ClassDef (126)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 2: 103 calls (0.4)
FunctionDef (103)
FunctionDef (103)
ClassDef (103)
None (103)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 3: 7 calls (0.03)
FunctionDef (7)
FunctionDef (7)
ClassDef (7)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 4: 6 calls (0.02)
FunctionDef (6)
FunctionDef (6)
ClassDef (6)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 5: 5 calls (0.02)
FunctionDef (5)
FunctionDef (5)
ClassDef (5)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 6: 3 calls (0.01)
FunctionDef (3)
FunctionDef (3)
ClassDef (3)
None (3)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 7: 3 calls (0.01)
FunctionDef (3)
FunctionDef (3)
ClassDef (3)
None (3)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 8: 2 calls (0.01)
FunctionDef (2)
FunctionDef (2)
ClassDef (2)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 9: 2 calls (0.01)
FunctionDef (2)
FunctionDef (2)
ClassDef (2)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 10: 1 calls (0.0)
FunctionDef (1)
FunctionDef (1)
ClassDef (1)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 11: 1 calls (0.0)
FunctionDef (1)
FunctionDef (1)
ClassDef (1)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )
Path 12: 1 calls (0.0)
FunctionDef (1)
FunctionDef (1)
ClassDef (1)
1def _check_signature(
2 self,
3 method1: nodes.FunctionDef,
4 refmethod: nodes.FunctionDef,
5 cls: nodes.ClassDef,
6 ) -> None:
7 """Check that the signature of the two given methods match."""
8 if not (
9 isinstance(method1, nodes.FunctionDef)
10 and isinstance(refmethod, nodes.FunctionDef)
11 ):
12 self.add_message(
13 "method-check-failed", args=(method1, refmethod), node=method1
14 )
15 return
16
17 instance = cls.instantiate_class()
18 method1 = astroid.scoped_nodes.function_to_method(method1, instance)
19 refmethod = astroid.scoped_nodes.function_to_method(refmethod, instance)
20
21 # Don't care about functions with unknown argument (builtins).
22 if method1.args.args is None or refmethod.args.args is None:
23 return
24
25 # Ignore private to class methods.
26 if is_attr_private(method1.name):
27 return
28 # Ignore setters, they have an implicit extra argument,
29 # which shouldn't be taken in consideration.
30 if is_property_setter(method1):
31 return
32
33 arg_differ_output = _different_parameters(
34 refmethod, method1, dummy_parameter_regex=self._dummy_rgx
35 )
36
37 class_type = "overriding"
38
39 if len(arg_differ_output) > 0:
40 for msg in arg_differ_output:
41 if "Number" in msg:
42 total_args_method1 = len(method1.args.args)
43 if method1.args.vararg:
44 total_args_method1 += 1
45 if method1.args.kwarg:
46 total_args_method1 += 1
47 if method1.args.kwonlyargs:
48 total_args_method1 += len(method1.args.kwonlyargs)
49 total_args_refmethod = len(refmethod.args.args)
50 if refmethod.args.vararg:
51 total_args_refmethod += 1
52 if refmethod.args.kwarg:
53 total_args_refmethod += 1
54 if refmethod.args.kwonlyargs:
55 total_args_refmethod += len(refmethod.args.kwonlyargs)
56 error_type = "arguments-differ"
57 msg_args = (
58 msg
59 + f"was {total_args_refmethod} in '{refmethod.parent.frame().name}.{refmethod.name}' and "
60 f"is now {total_args_method1} in",
61 class_type,
62 f"{method1.parent.frame().name}.{method1.name}",
63 )
64 elif "renamed" in msg:
65 error_type = "arguments-renamed"
66 msg_args = (
67 msg,
68 class_type,
69 f"{method1.parent.frame().name}.{method1.name}",
70 )
71 else:
72 error_type = "arguments-differ"
73 msg_args = (
74 msg,
75 class_type,
76 f"{method1.parent.frame().name}.{method1.name}",
77 )
78 self.add_message(error_type, args=msg_args, node=method1)
79 elif (
80 len(method1.args.defaults) < len(refmethod.args.defaults)
81 and not method1.args.vararg
82 ):
83 class_type = "overridden"
84 self.add_message(
85 "signature-differs", args=(class_type, method1.name), node=method1
86 )