Skip to content

Commit

Permalink
Add 'of' to GoogleDocstring multiple type (#2884)
Browse files Browse the repository at this point in the history
A docstring of the following form should pass (see https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html, search for ':obj:list of :obj:str')

def my_func(self):
    """This is a docstring.

    Returns
    -------
    :obj:`list` of :obj:`str`
        List of strings
    """
    return ["hi", "bye"] #@
  • Loading branch information
znicholls authored and PCManticore committed Apr 29, 2019
1 parent 377e82f commit b1ee385
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,6 @@ contributors:
* Taewon Kim : contributor

* Daniil Kharkov: contributor

* Zeb Nicholls: contributor
- Made W9011 compatible with 'of' syntax in return types
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ What's New in Pylint 2.4.0?

Release date: TBA

* Allow of in `GoogleDocstring.re_multiple_type`

* Added `subprocess-run-check` to handle subrocess.run without explicitly set `check` keyword.

Close #2848
Expand Down
14 changes: 14 additions & 0 deletions doc/whatsnew/2.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ The following imports do not trigger an ``ungrouped-imports`` anymore ::
import zipfile
from unittest import TestCase
from unittest.mock import MagicMock
* The checker for missing return documentation is now more flexible.

The following does not trigger a ``missing-return-doc`` anymore ::

def my_func(self):
"""This is a docstring.

Returns
-------
:obj:`list` of :obj:`str`
List of strings
"""
return ["hi", "bye"] #@
2 changes: 1 addition & 1 deletion pylint/extensions/_check_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class GoogleDocstring(Docstring):

re_multiple_type = r"""
(?:{container_type}|{type}|{xref})
(?:\s+or\s+(?:{container_type}|{type}|{xref}))*
(?:\s+(?:of|or)\s+(?:{container_type}|{type}|{xref}))*
""".format(
type=re_type, xref=re_xref, container_type=re_container_type
)
Expand Down
15 changes: 15 additions & 0 deletions pylint/test/extensions/test_check_return_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ def my_func(self):
with self.assertNoMessages():
self.checker.visit_return(return_node)

def test_find_numpy_returns_with_of(self):
return_node = astroid.extract_node('''
def my_func(self):
"""This is a docstring.
Returns
-------
:obj:`list` of :obj:`str`
List of strings
"""
return ["hi", "bye"] #@
''')
with self.assertNoMessages():
self.checker.visit_return(return_node)

def test_ignores_sphinx_return_none(self):
return_node = astroid.extract_node('''
def my_func(self, doc_type):
Expand Down

0 comments on commit b1ee385

Please sign in to comment.