diff options
author | Ashley Whetter <AWhetter@users.noreply.github.com> | 2019-10-17 00:04:23 -0700 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-10-17 09:04:45 +0200 |
commit | 89a18eff3f10b2ca9bd3a16ced978580586ad89e (patch) | |
tree | 43e951ccdc4fdda659b0c344a5a02c24dbd88b54 | |
parent | 30c1504b3c3eba44cf9fa2614dedc812810c7dc8 (diff) | |
download | pylint-git-89a18eff3f10b2ca9bd3a16ced978580586ad89e.tar.gz |
Fixed ``missing-yield-type-doc`` ignoring type annotation (#3195)
Closes #3185
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | pylint/extensions/docparams.py | 2 | ||||
-rw-r--r-- | tests/extensions/test_check_return_docs.py | 15 | ||||
-rw-r--r-- | tests/extensions/test_check_yields_docs.py | 35 |
4 files changed, 42 insertions, 17 deletions
@@ -29,6 +29,11 @@ Release date: TBA Close #3150 +* Fixed ``missing-yield-type-doc`` getting incorrectly raised when + a generator does not document a yield type but has a type annotation. + + Closes #3185 + What's New in Pylint 2.4.2? =========================== @@ -362,7 +367,7 @@ must rename the associated identification. * Allow the choice of f-strings as a valid way of formatting logging strings. -Closes #2395 + Closes #2395 * Added ``--list-msgs-enabled`` command to list all enabled and disabled messages given the current RC file and command line arguments. diff --git a/pylint/extensions/docparams.py b/pylint/extensions/docparams.py index ca5fed23c..d5a15a4f3 100644 --- a/pylint/extensions/docparams.py +++ b/pylint/extensions/docparams.py @@ -316,7 +316,7 @@ class DocstringParameterChecker(BaseChecker): if not doc_has_yields: self.add_message("missing-yield-doc", node=func_node) - if not doc_has_yields_type: + if not (doc_has_yields_type or func_node.returns): self.add_message("missing-yield-type-doc", node=func_node) def visit_yieldfrom(self, node): diff --git a/tests/extensions/test_check_return_docs.py b/tests/extensions/test_check_return_docs.py index c8758b43c..824a5d765 100644 --- a/tests/extensions/test_check_return_docs.py +++ b/tests/extensions/test_check_return_docs.py @@ -76,21 +76,6 @@ class TestDocstringCheckerReturn(CheckerTestCase): ): self.checker.visit_return(return_node) - def test_sphinx_returns_annotations(self): - node = astroid.extract_node( - ''' - def my_func(self) -> bool: - """This is a docstring. - - :returns: Always False - """ - return False - ''' - ) - return_node = node.body[0] - with self.assertNoMessages(): - self.checker.visit_return(return_node) - def test_sphinx_missing_return_type_with_annotations(self): node = astroid.extract_node( ''' diff --git a/tests/extensions/test_check_yields_docs.py b/tests/extensions/test_check_yields_docs.py index 4987e75c6..3107cb2b1 100644 --- a/tests/extensions/test_check_yields_docs.py +++ b/tests/extensions/test_check_yields_docs.py @@ -445,3 +445,38 @@ class TestDocstringCheckerYield(CheckerTestCase): ) with self.assertAddsMessages(Message(msg_id="redundant-yields-doc", node=node)): self.checker.visit_functiondef(node) + + def test_sphinx_missing_yield_type_with_annotations(self): + node = astroid.extract_node( + ''' + import typing + + def generator() -> typing.Iterator[int]: + """A simple function for checking type hints. + + :returns: The number 0 + """ + yield 0 + ''' + ) + yield_node = node.body[0] + with self.assertNoMessages(): + self.checker.visit_yield(yield_node) + + def test_google_missing_yield_type_with_annotations(self): + node = astroid.extract_node( + ''' + import typing + + def generator() -> typing.Iterator[int]: + """A simple function for checking type hints. + + Yields: + The number 0 + """ + yield 0 + ''' + ) + yield_node = node.body[0] + with self.assertNoMessages(): + self.checker.visit_yield(yield_node) |