Closes #1831: [Napoleon] If name is not found in NumPy Doc Returns section, regard the whole line as the type

This commit is contained in:
Rob Ruana 2015-04-03 21:32:05 -04:00
parent 0b60eafe0e
commit 80eb821ec8
2 changed files with 63 additions and 0 deletions

View File

@ -720,6 +720,8 @@ class NumpyDocstring(GoogleDocstring):
line = next(self._line_iter)
if parse_type:
_name, _, _type = line.partition(':')
if not _name:
_type = line
else:
_name, _type = line, ''
_name, _type = _name.strip(), _type.strip()

View File

@ -326,6 +326,24 @@ Attributes:
"""
self.assertEqual(expected, actual)
def test_code_block_in_returns_section(self):
docstring = """
Returns:
foobar: foo::
codecode
codecode
"""
expected = """
:returns: foo::
codecode
codecode
:rtype: foobar
"""
actual = str(GoogleDocstring(docstring))
self.assertEqual(expected, actual)
class NumpyDocstringTest(BaseDocstringTest):
docstrings = [(
@ -588,3 +606,46 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None)
relationship
"""
self.assertEqual(expected, actual)
def test_colon_in_return_type(self):
docstring = """
Summary
Returns
-------
:py:class:`~my_mod.my_class`
an instance of :py:class:`~my_mod.my_class`
"""
expected = """
Summary
:returns: an instance of :py:class:`~my_mod.my_class`
:rtype: :py:class:`~my_mod.my_class`
"""
config = Config()
app = mock.Mock()
actual = str(NumpyDocstring(docstring, config, app, "method"))
self.assertEqual(expected, actual)
def test_underscore_in_attribute(self):
docstring = """
Attributes
----------
arg_ : type
some description
"""
expected = """
:ivar arg_: some description
:vartype arg_: type
"""
config = Config(napoleon_use_ivar=True)
app = mock.Mock()
actual = str(NumpyDocstring(docstring, config, app, "class"))
self.assertEqual(expected, actual)