53
53
f"{ MORE_INFO_BASE } { MULT_YIELDS_SECTIONS_IN_DOCSTR_CODE .lower ()} "
54
54
)
55
55
56
+ PRIVATE_FUNCTION_PATTERN = r"_[^_].*"
56
57
TEST_FILENAME_PATTERN_ARG_NAME = "--docstrings-complete-test-filename-pattern"
57
58
TEST_FILENAME_PATTERN_DEFAULT = r"test_.*\.py"
58
59
TEST_FUNCTION_PATTERN_ARG_NAME = "--docstrings-complete-test-function-pattern"
@@ -77,22 +78,26 @@ def _cli_arg_name_to_attr(cli_arg_name: str) -> str:
77
78
78
79
79
80
def _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 ,
81
85
) -> Iterator [types_ .Problem ]:
82
86
"""Check function/ method returns section.
83
87
84
88
Args:
85
89
docstr_info: Information about the docstring.
86
90
docstr_node: The docstring node.
87
91
return_nodes: The return nodes of the function.
92
+ is_private: If the function for the docstring is private.
88
93
89
94
Yields:
90
95
All the problems with the returns section.
91
96
"""
92
97
return_nodes_with_value = list (node for node in return_nodes if node .value is not None )
93
98
94
99
# 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 :
96
101
yield from (
97
102
types_ .Problem (node .lineno , node .col_offset , RETURNS_SECTION_NOT_IN_DOCSTR_MSG )
98
103
for node in return_nodes_with_value
@@ -117,21 +122,23 @@ def _check_yields(
117
122
docstr_info : docstring .Docstring ,
118
123
docstr_node : ast .Constant ,
119
124
yield_nodes : Iterable [ast .Yield | ast .YieldFrom ],
125
+ is_private : bool ,
120
126
) -> Iterator [types_ .Problem ]:
121
127
"""Check function/ method yields section.
122
128
123
129
Args:
124
130
docstr_info: Information about the docstring.
125
131
docstr_node: The docstring node.
126
132
yield_nodes: The yield and yield from nodes of the function.
133
+ is_private: If the function for the docstring is private.
127
134
128
135
Yields:
129
136
All the problems with the yields section.
130
137
"""
131
138
yield_nodes_with_value = list (node for node in yield_nodes if node .value is not None )
132
139
133
140
# 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 :
135
142
yield from (
136
143
types_ .Problem (node .lineno , node .col_offset , YIELDS_SECTION_NOT_IN_DOCSTR_MSG )
137
144
for node in yield_nodes_with_value
@@ -372,11 +379,17 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
372
379
and isinstance (node .body [0 ].value , ast .Constant )
373
380
and isinstance (node .body [0 ].value .value , str )
374
381
):
382
+ is_private = bool (re .match (PRIVATE_FUNCTION_PATTERN , node .name ))
375
383
# Check args
376
384
docstr_info = docstring .parse (value = node .body [0 ].value .value )
377
385
docstr_node = node .body [0 ].value
378
386
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
+ )
380
393
)
381
394
382
395
# Check returns
@@ -387,6 +400,7 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
387
400
docstr_info = docstr_info ,
388
401
docstr_node = docstr_node ,
389
402
return_nodes = visitor_within_function .return_nodes ,
403
+ is_private = is_private ,
390
404
)
391
405
)
392
406
@@ -396,6 +410,7 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
396
410
docstr_info = docstr_info ,
397
411
docstr_node = docstr_node ,
398
412
yield_nodes = visitor_within_function .yield_nodes ,
413
+ is_private = is_private ,
399
414
)
400
415
)
401
416
@@ -405,6 +420,7 @@ def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> No
405
420
docstr_info = docstr_info ,
406
421
docstr_node = docstr_node ,
407
422
raise_nodes = visitor_within_function .raise_nodes ,
423
+ is_private = is_private ,
408
424
)
409
425
)
410
426
0 commit comments