Skip to content

Commit

Permalink
Fixed missing-yield-type-doc ignoring type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
AWhetter committed Oct 17, 2019
1 parent 6df0b3e commit 61b5ae4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
7 changes: 6 additions & 1 deletion ChangeLog
Expand Up @@ -386,10 +386,15 @@ 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.

* 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.3.0?
===========================

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)

0 comments on commit 61b5ae4

Please sign in to comment.