Method: pylint.extensions.docparams.DocstringParameterChecker.check_arguments_in_docstring
Calls: 301, Exceptions: 0, Paths: 23Back
Path 1: 115 calls (0.38)
GoogleDocstring (39) SphinxDocstring (37) NumpyDocstring (34) Docstring (5)
Arguments (115)
FunctionDef (115)
None (115)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 2: 69 calls (0.23)
SphinxDocstring (28) NumpyDocstring (25) GoogleDocstring (16)
Arguments (69)
FunctionDef (65) ClassDef (4)
None (69)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 3: 22 calls (0.07)
Docstring (22)
Arguments (22)
FunctionDef (17) ClassDef (5)
None (15) True (7)
None (22)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 4: 18 calls (0.06)
GoogleDocstring (10) SphinxDocstring (6) Docstring (2)
Arguments (18)
FunctionDef (18)
None (18)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 5: 14 calls (0.05)
Docstring (11) NumpyDocstring (3)
Arguments (14)
FunctionDef (10) AsyncFunctionDef (4)
None (14)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 6: 12 calls (0.04)
GoogleDocstring (7) SphinxDocstring (5)
Arguments (12)
FunctionDef (12)
None (12)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 7: 11 calls (0.04)
GoogleDocstring (4) SphinxDocstring (4) NumpyDocstring (3)
Arguments (11)
FunctionDef (11)
None (11)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 8: 9 calls (0.03)
SphinxDocstring (4) NumpyDocstring (3) GoogleDocstring (2)
Arguments (9)
FunctionDef (9)
None (9)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 9: 8 calls (0.03)
Docstring (2) GoogleDocstring (2) NumpyDocstring (2) SphinxDocstring (2)
Arguments (8)
FunctionDef (7) ClassDef (1)
None (8)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 10: 6 calls (0.02)
GoogleDocstring (2) NumpyDocstring (2) SphinxDocstring (2)
Arguments (6)
ClassDef (3) FunctionDef (3)
True (6)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 11: 3 calls (0.01)
Docstring (3)
Arguments (3)
FunctionDef (2) ClassDef (1)
True (3)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 12: 2 calls (0.01)
SphinxDocstring (1) GoogleDocstring (1)
Arguments (2)
FunctionDef (2)
None (2)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 13: 2 calls (0.01)
GoogleDocstring (1) NumpyDocstring (1)
Arguments (2)
FunctionDef (2)
None (2)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 14: 1 calls (0.0)
SphinxDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 15: 1 calls (0.0)
SphinxDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 16: 1 calls (0.0)
SphinxDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 17: 1 calls (0.0)
SphinxDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 18: 1 calls (0.0)
SphinxDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 19: 1 calls (0.0)
NumpyDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 20: 1 calls (0.0)
NumpyDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 21: 1 calls (0.0)
SphinxDocstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 22: 1 calls (0.0)
Docstring (1)
Arguments (1)
ClassDef (1)
True (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )
Path 23: 1 calls (0.0)
Docstring (1)
Arguments (1)
FunctionDef (1)
None (1)
1def check_arguments_in_docstring(
2 self,
3 doc: Docstring,
4 arguments_node: astroid.Arguments,
5 warning_node: astroid.NodeNG,
6 accept_no_param_doc: bool | None = None,
7 ) -> None:
8 """Check that all parameters are consistent with the parameters mentioned
9 in the parameter documentation (e.g. the Sphinx tags 'param' and 'type').
10
11 * Undocumented parameters except 'self' are noticed.
12 * Undocumented parameter types except for 'self' and the ``*<args>``
13 and ``**<kwargs>`` parameters are noticed.
14 * Parameters mentioned in the parameter documentation that don't or no
15 longer exist in the function parameter list are noticed.
16 * If the text "For the parameters, see" or "For the other parameters,
17 see" (ignoring additional white-space) is mentioned in the docstring,
18 missing parameter documentation is tolerated.
19 * If there's no Sphinx style, Google style or NumPy style parameter
20 documentation at all, i.e. ``:param`` is never mentioned etc., the
21 checker assumes that the parameters are documented in another format
22 and the absence is tolerated.
23
24 :param doc: Docstring for the function, method or class.
25 :type doc: :class:`Docstring`
26
27 :param arguments_node: Arguments node for the function, method or
28 class constructor.
29 :type arguments_node: :class:`astroid.scoped_nodes.Arguments`
30
31 :param warning_node: The node to assign the warnings to
32 :type warning_node: :class:`astroid.scoped_nodes.Node`
33
34 :param accept_no_param_doc: Whether to allow no parameters to be
35 documented. If None then this value is read from the configuration.
36 :type accept_no_param_doc: bool or None
37 """
38 # Tolerate missing param or type declarations if there is a link to
39 # another method carrying the same name.
40 if not doc.doc:
41 return
42
43 if accept_no_param_doc is None:
44 accept_no_param_doc = self.linter.config.accept_no_param_doc
45 tolerate_missing_params = doc.params_documented_elsewhere()
46
47 # Collect the function arguments.
48 expected_argument_names = {arg.name for arg in arguments_node.args}
49 expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
50 expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
51 not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
52
53 expected_but_ignored_argument_names = set()
54 ignored_argument_names = self.linter.config.ignored_argument_names
55 if ignored_argument_names:
56 expected_but_ignored_argument_names = {
57 arg
58 for arg in expected_argument_names
59 if ignored_argument_names.match(arg)
60 }
61
62 if arguments_node.vararg is not None:
63 expected_argument_names.add(f"*{arguments_node.vararg}")
64 not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
65 if arguments_node.kwarg is not None:
66 expected_argument_names.add(f"**{arguments_node.kwarg}")
67 not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
68 params_with_doc, params_with_type = doc.match_param_docs()
69 # Tolerate no parameter documentation at all.
70 if not params_with_doc and not params_with_type and accept_no_param_doc:
71 tolerate_missing_params = True
72
73 # This is before the update of param_with_type because this must check only
74 # the type documented in a docstring, not the one using pep484
75 # See #4117 and #4593
76 self._compare_ignored_args(
77 params_with_type,
78 "useless-type-doc",
79 expected_but_ignored_argument_names,
80 warning_node,
81 )
82 for index, arg_name in enumerate(arguments_node.args):
83 if arguments_node.annotations[index]:
84 params_with_type.add(arg_name.name)
85 for index, arg_name in enumerate(arguments_node.kwonlyargs):
86 if arguments_node.kwonlyargs_annotations[index]:
87 params_with_type.add(arg_name.name)
88 for index, arg_name in enumerate(arguments_node.posonlyargs):
89 if arguments_node.posonlyargs_annotations[index]:
90 params_with_type.add(arg_name.name)
91
92 if not tolerate_missing_params:
93 missing_param_doc = (expected_argument_names - params_with_doc) - (
94 self.not_needed_param_in_docstring | expected_but_ignored_argument_names
95 )
96 missing_type_doc = (expected_argument_names - params_with_type) - (
97 not_needed_type_in_docstring | expected_but_ignored_argument_names
98 )
99 if (
100 missing_param_doc == expected_argument_names == missing_type_doc
101 and len(expected_argument_names) != 0
102 ):
103 self.add_message(
104 "missing-any-param-doc",
105 args=(warning_node.name,),
106 node=warning_node,
107 confidence=HIGH,
108 )
109 else:
110 self._compare_missing_args(
111 params_with_doc,
112 "missing-param-doc",
113 self.not_needed_param_in_docstring
114 | expected_but_ignored_argument_names,
115 expected_argument_names,
116 warning_node,
117 )
118 self._compare_missing_args(
119 params_with_type,
120 "missing-type-doc",
121 not_needed_type_in_docstring | expected_but_ignored_argument_names,
122 expected_argument_names,
123 warning_node,
124 )
125
126 self._compare_different_args(
127 params_with_doc,
128 "differing-param-doc",
129 self.not_needed_param_in_docstring,
130 expected_argument_names,
131 warning_node,
132 )
133 self._compare_different_args(
134 params_with_type,
135 "differing-type-doc",
136 not_needed_type_in_docstring,
137 expected_argument_names,
138 warning_node,
139 )
140 self._compare_ignored_args(
141 params_with_doc,
142 "useless-param-doc",
143 expected_but_ignored_argument_names,
144 warning_node,
145 )