Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing-yield-type-doc ignoring type annotation #3195

Merged
merged 1 commit into from Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion ChangeLog
Expand Up @@ -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?
===========================
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion pylint/extensions/docparams.py
Expand Up @@ -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):
Expand Down
15 changes: 0 additions & 15 deletions tests/extensions/test_check_return_docs.py
Expand Up @@ -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(
'''
Expand Down
35 changes: 35 additions & 0 deletions tests/extensions/test_check_yields_docs.py
Expand Up @@ -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)