5353 f"{ MORE_INFO_BASE } { MULT_YIELDS_SECTIONS_IN_DOCSTR_CODE .lower ()} "
5454)
5555
56+ PRIVATE_FUNCTION_PATTERN = r"_[^_].*"
5657TEST_FILENAME_PATTERN_ARG_NAME = "--docstrings-complete-test-filename-pattern"
5758TEST_FILENAME_PATTERN_DEFAULT = r"test_.*\.py"
5859TEST_FUNCTION_PATTERN_ARG_NAME = "--docstrings-complete-test-function-pattern"
@@ -77,22 +78,26 @@ def _cli_arg_name_to_attr(cli_arg_name: str) -> str:
7778
7879
7980def _check_returns (
80- docstr_info : docstring .Docstring , docstr_node : ast .Constant , return_nodes : Iterable [ast .Return ]
81+ docstr_info : docstring .Docstring ,
82+ docstr_node : ast .Constant ,
83+ return_nodes : Iterable [ast .Return ],
84+ is_private : bool ,
8185) -> Iterator [types_ .Problem ]:
8286 """Check function/ method returns section.
8387
8488 Args:
8589 docstr_info: Information about the docstring.
8690 docstr_node: The docstring node.
8791 return_nodes: The return nodes of the function.
92+ is_private: If the function for the docstring is private.
8893
8994 Yields:
9095 All the problems with the returns section.
9196 """
9297 return_nodes_with_value = list (node for node in return_nodes if node .value is not None )
9398
9499 # Check for return statements with value and no returns section in docstring
95- if return_nodes_with_value and not docstr_info .returns_sections :
100+ if return_nodes_with_value and not docstr_info .returns_sections and not is_private :
96101 yield from (
97102 types_ .Problem (node .lineno , node .col_offset , RETURNS_SECTION_NOT_IN_DOCSTR_MSG )
98103 for node in return_nodes_with_value
@@ -117,21 +122,23 @@ def _check_yields(
117122 docstr_info : docstring .Docstring ,
118123 docstr_node : ast .Constant ,
119124 yield_nodes : Iterable [ast .Yield | ast .YieldFrom ],
125+ is_private : bool ,
120126) -> Iterator [types_ .Problem ]:
121127 """Check function/ method yields section.
122128
123129 Args:
124130 docstr_info: Information about the docstring.
125131 docstr_node: The docstring node.
126132 yield_nodes: The yield and yield from nodes of the function.
133+ is_private: If the function for the docstring is private.
127134
128135 Yields:
129136 All the problems with the yields section.
130137 """
131138 yield_nodes_with_value = list (node for node in yield_nodes if node .value is not None )
132139
133140 # Check for yield statements with value and no yields section in docstring
134- if yield_nodes_with_value and not docstr_info .yields_sections :
141+ if yield_nodes_with_value and not docstr_info .yields_sections and not is_private :
135142 yield from (
136143 types_ .Problem (node .lineno , node .col_offset , YIELDS_SECTION_NOT_IN_DOCSTR_MSG )
137144 for node in yield_nodes_with_value
@@ -372,11 +379,17 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
372379 and isinstance (node .body [0 ].value , ast .Constant )
373380 and isinstance (node .body [0 ].value .value , str )
374381 ):
382+ is_private = bool (re .match (PRIVATE_FUNCTION_PATTERN , node .name ))
375383 # Check args
376384 docstr_info = docstring .parse (value = node .body [0 ].value .value )
377385 docstr_node = node .body [0 ].value
378386 self .problems .extend (
379- args .check (docstr_info = docstr_info , docstr_node = docstr_node , args = node .args )
387+ args .check (
388+ docstr_info = docstr_info ,
389+ docstr_node = docstr_node ,
390+ args = node .args ,
391+ is_private = is_private ,
392+ )
380393 )
381394
382395 # Check returns
@@ -387,6 +400,7 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
387400 docstr_info = docstr_info ,
388401 docstr_node = docstr_node ,
389402 return_nodes = visitor_within_function .return_nodes ,
403+ is_private = is_private ,
390404 )
391405 )
392406
@@ -396,6 +410,7 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
396410 docstr_info = docstr_info ,
397411 docstr_node = docstr_node ,
398412 yield_nodes = visitor_within_function .yield_nodes ,
413+ is_private = is_private ,
399414 )
400415 )
401416
@@ -405,6 +420,7 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
405420 docstr_info = docstr_info ,
406421 docstr_node = docstr_node ,
407422 raise_nodes = visitor_within_function .raise_nodes ,
423+ is_private = is_private ,
408424 )
409425 )
410426
0 commit comments