Method: pylint.checkers.classes.special_methods_checker.SpecialMethodsChecker._check_unexpected_method_signature
Calls: 656, Exceptions: 0, Paths: 10Back
Path 1: 353 calls (0.54)
FunctionDef (353)
None (353)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 2: 273 calls (0.42)
FunctionDef (270) AsyncFunctionDef (3)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 3: 11 calls (0.02)
FunctionDef (11)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 4: 10 calls (0.02)
FunctionDef (10)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 5: 3 calls (0.0)
FunctionDef (3)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 6: 2 calls (0.0)
FunctionDef (2)
None (2)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 7: 1 calls (0.0)
FunctionDef (1)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 8: 1 calls (0.0)
FunctionDef (1)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 9: 1 calls (0.0)
FunctionDef (1)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )
Path 10: 1 calls (0.0)
FunctionDef (1)
1def _check_unexpected_method_signature(self, node: nodes.FunctionDef) -> None:
2 expected_params = SPECIAL_METHODS_PARAMS[node.name]
3
4 if expected_params is None:
5 # This can support a variable number of parameters.
6 return
7 if not node.args.args and not node.args.vararg:
8 # Method has no parameter, will be caught
9 # by no-method-argument.
10 return
11
12 if decorated_with(node, ["builtins.staticmethod"]):
13 # We expect to not take in consideration self.
14 all_args = node.args.args
15 else:
16 all_args = node.args.args[1:]
17 mandatory = len(all_args) - len(node.args.defaults)
18 optional = len(node.args.defaults)
19 current_params = mandatory + optional
20
21 emit = False # If we don't know we choose a false negative
22 if isinstance(expected_params, tuple):
23 # The expected number of parameters can be any value from this
24 # tuple, although the user should implement the method
25 # to take all of them in consideration.
26 emit = mandatory not in expected_params
27 # mypy thinks that expected_params has type tuple[int, int] | int | None
28 # But at this point it must be 'tuple[int, int]' because of the type check
29 expected_params = f"between {expected_params[0]} or {expected_params[1]}" # type: ignore[assignment]
30 else:
31 # If the number of mandatory parameters doesn't
32 # suffice, the expected parameters for this
33 # function will be deduced from the optional
34 # parameters.
35 rest = expected_params - mandatory
36 if rest == 0:
37 emit = False
38 elif rest < 0:
39 emit = True
40 elif rest > 0:
41 emit = not ((optional - rest) >= 0 or node.args.vararg)
42
43 if emit:
44 verb = "was" if current_params <= 1 else "were"
45 self.add_message(
46 "unexpected-special-method-signature",
47 args=(node.name, expected_params, current_params, verb),
48 node=node,
49 )