Skip to content

Commit

Permalink
Make missing-yield/raises-doc respect no-docstring-rgx option
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord authored and Pierre-Sassoulas committed Sep 6, 2022
1 parent f2ecf4f commit 7848356
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc/whatsnew/fragments/4743.bugfix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
``missing-return-doc`` now respects the ``no-docstring-rgx`` option.
``missing-return-doc``, ``missing-raises-doc`` and ``missing-yields-doc`` now respect
the ``no-docstring-rgx`` option.

Closes #4743
10 changes: 10 additions & 0 deletions pylint/extensions/docparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ def visit_raise(self, node: nodes.Raise) -> None:
if not isinstance(func_node, astroid.FunctionDef):
return

# skip functions that match the 'no-docstring-rgx' config option
no_docstring_rgx = self.linter.config.no_docstring_rgx
if no_docstring_rgx and re.match(no_docstring_rgx, func_node.name):
return

expected_excs = utils.possible_exc_types(node)

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

# skip functions that match the 'no-docstring-rgx' config option
no_docstring_rgx = self.linter.config.no_docstring_rgx
if no_docstring_rgx and re.match(no_docstring_rgx, func_node.name):
return

doc = utils.docstringify(
func_node.doc_node, self.linter.config.default_docstring_type
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
def test_warns_unknown_style(self): # [missing-raises-doc]
"""This is a docstring."""
raise RuntimeError("hi")


# This function doesn't require a docstring, because its name starts
# with an '_' (no-docstring-rgx):
def _function(some_arg: int):
"""This is a docstring."""
raise ValueError
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
"""Tests for missing-yield-doc and missing-yield-type-doc with accept-no-yields-doc = no"""
# pylint: disable=missing-function-docstring, unused-argument, function-redefined

from typing import Iterator


# Test missing docstring
def my_func(self): # [missing-yield-doc, missing-yield-type-doc]
yield False


# This function doesn't require a docstring, because its name starts
# with an '_' (no-docstring-rgx):
def _function(some_arg: int) -> Iterator[int]:
yield some_arg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
missing-yield-doc:6:0:6:11:my_func:Missing yield documentation:HIGH
missing-yield-type-doc:6:0:6:11:my_func:Missing yield type documentation:HIGH
missing-yield-doc:8:0:8:11:my_func:Missing yield documentation:HIGH
missing-yield-type-doc:8:0:8:11:my_func:Missing yield type documentation:HIGH

0 comments on commit 7848356

Please sign in to comment.