Skip to content

Commit 262723a

Browse files
DanielNoordPierre-Sassoulas
authored andcommitted
Make missing-yield/raises-doc respect no-docstring-rgx option
1 parent a21af6a commit 262723a

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

doc/whatsnew/fragments/4743.bugfix

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
``missing-return-doc`` now respects the ``no-docstring-rgx`` option.
1+
``missing-return-doc``, ``missing-raises-doc`` and ``missing-yields-doc`` now respect
2+
the ``no-docstring-rgx`` option.
23

34
Closes #4743

pylint/extensions/docparams.py

+10
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ def visit_raise(self, node: nodes.Raise) -> None:
278278
if not isinstance(func_node, astroid.FunctionDef):
279279
return
280280

281+
# skip functions that match the 'no-docstring-rgx' config option
282+
no_docstring_rgx = self.linter.config.no_docstring_rgx
283+
if no_docstring_rgx and re.match(no_docstring_rgx, func_node.name):
284+
return
285+
281286
expected_excs = utils.possible_exc_types(node)
282287

283288
if not expected_excs:
@@ -355,6 +360,11 @@ def visit_yield(self, node: nodes.Yield | nodes.YieldFrom) -> None:
355360
if not isinstance(func_node, astroid.FunctionDef):
356361
return
357362

363+
# skip functions that match the 'no-docstring-rgx' config option
364+
no_docstring_rgx = self.linter.config.no_docstring_rgx
365+
if no_docstring_rgx and re.match(no_docstring_rgx, func_node.name):
366+
return
367+
358368
doc = utils.docstringify(
359369
func_node.doc_node, self.linter.config.default_docstring_type
360370
)

tests/functional/ext/docparams/raise/missing_raises_doc_required.py

+7
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@
66
def test_warns_unknown_style(self): # [missing-raises-doc]
77
"""This is a docstring."""
88
raise RuntimeError("hi")
9+
10+
11+
# This function doesn't require a docstring, because its name starts
12+
# with an '_' (no-docstring-rgx):
13+
def _function(some_arg: int):
14+
"""This is a docstring."""
15+
raise ValueError
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
"""Tests for missing-yield-doc and missing-yield-type-doc with accept-no-yields-doc = no"""
22
# pylint: disable=missing-function-docstring, unused-argument, function-redefined
33

4+
from typing import Iterator
5+
46

57
# Test missing docstring
68
def my_func(self): # [missing-yield-doc, missing-yield-type-doc]
79
yield False
10+
11+
12+
# This function doesn't require a docstring, because its name starts
13+
# with an '_' (no-docstring-rgx):
14+
def _function(some_arg: int) -> Iterator[int]:
15+
yield some_arg
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
missing-yield-doc:6:0:6:11:my_func:Missing yield documentation:HIGH
2-
missing-yield-type-doc:6:0:6:11:my_func:Missing yield type documentation:HIGH
1+
missing-yield-doc:8:0:8:11:my_func:Missing yield documentation:HIGH
2+
missing-yield-type-doc:8:0:8:11:my_func:Missing yield type documentation:HIGH

0 commit comments

Comments
 (0)