From d06c2d8784bc27c42c7e95d5866356b5e6ac24cd Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Wed, 16 Oct 2019 21:33:38 -0700 Subject: [PATCH] Fixed ``missing-yield-type-doc`` ignoring type annotation Closes #3185 --- ChangeLog | 7 ++++- pylint/extensions/docparams.py | 2 +- tests/extensions/test_check_return_docs.py | 15 ---------- tests/extensions/test_check_yields_docs.py | 35 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index b64a725cd4..a3eb5fed60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -53,6 +53,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? =========================== @@ -386,7 +391,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 ca5fed23ce..d5a15a4f3e 100644 --- a/pylint/extensions/docparams.py +++ b/pylint/extensions/docparams.py @@ -316,7 +316,7 @@ def visit_yield(self, node): 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 c8758b43c0..824a5d7656 100644 --- a/tests/extensions/test_check_return_docs.py +++ b/tests/extensions/test_check_return_docs.py @@ -76,21 +76,6 @@ def my_func(self): ): 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 4987e75c64..3107cb2b1b 100644 --- a/tests/extensions/test_check_yields_docs.py +++ b/tests/extensions/test_check_yields_docs.py @@ -445,3 +445,38 @@ def my_func(self): ) 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)