Closes #1670: Fix napoleon handling of *args and **kwargs parameters

This commit is contained in:
Rob Ruana
2015-01-12 17:08:51 -05:00
parent dee3e60ee6
commit 9df7b53782
2 changed files with 52 additions and 2 deletions

View File

@@ -23,8 +23,9 @@ from sphinx.util.pycompat import UnicodeMixin
_directive_regex = re.compile(r'\.\. \S+::')
_google_untyped_arg_regex = re.compile(r'\s*(\w+)\s*:\s*(.*)')
_google_typed_arg_regex = re.compile(r'\s*(\w+)\s*\(\s*(.+?)\s*\)\s*:\s*(.*)')
_google_untyped_arg_regex = re.compile(r'\s*(\*?\*?\w+)\s*:\s*(.*)')
_google_typed_arg_regex = re.compile(r'\s*(\*?\*?\w+)\s*\(\s*(.+?)\s*\)\s*:'
r'\s*(.*)')
class GoogleDocstring(UnicodeMixin):
@@ -90,6 +91,7 @@ class GoogleDocstring(UnicodeMixin):
<BLANKLINE>
:returns: Description of return value.
:rtype: str
<BLANKLINE>
"""
def __init__(self, docstring, config=None, app=None, what='', name='',
@@ -215,6 +217,11 @@ class GoogleDocstring(UnicodeMixin):
_name = match.group(1)
_desc = match.group(2)
if _name[:2] == '**':
_name = r'\*\*'+_name[2:]
elif _name[:1] == '*':
_name = r'\*'+_name[1:]
if prefer_type and not _type:
_type, _name = _name, _type
indent = self._get_indent(line) + 1
@@ -663,6 +670,7 @@ class NumpyDocstring(GoogleDocstring):
<BLANKLINE>
:returns: Description of return value.
:rtype: str
<BLANKLINE>
Methods
-------

View File

@@ -155,6 +155,26 @@ class GoogleDocstringTest(BaseDocstringTest):
:returns: Extended
description of return value"""
), (
"""
Single line summary
Args:
arg1(str):Extended
description of arg1
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.
""",
"""
Single line summary
:Parameters: * **arg1** (*str*) --
Extended
description of arg1
* **\\*args** --
Variable length argument list.
* **\\*\\*kwargs** --
Arbitrary keyword arguments."""
)]
def test_docstrings(self):
@@ -335,6 +355,28 @@ class NumpyDocstringTest(BaseDocstringTest):
:returns: *str* --
Extended
description of return value"""
), (
"""
Single line summary
Parameters
----------
arg1:str
Extended description of arg1
*args:
Variable length argument list.
**kwargs:
Arbitrary keyword arguments.
""",
"""
Single line summary
:Parameters: * **arg1** (*str*) --
Extended description of arg1
* ***args** --
Variable length argument list.
* ****kwargs** --
Arbitrary keyword arguments."""
)]
def test_docstrings(self):