Skip to content

Commit

Permalink
Merge pull request #155 from has2k1/escape-args-kwargs
Browse files Browse the repository at this point in the history
Escape the * in *args and **kwargs
  • Loading branch information
rgommers committed Apr 1, 2018
2 parents 9e526a9 + 5a311f3 commit 9cd5944
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
11 changes: 10 additions & 1 deletion numpydoc/docscrape_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ def _str_returns(self, name='Returns'):
out += ['']
return out

def _escape_args_and_kwargs(self, name):
if name[:2] == '**':
return r'\*\*' + name[2:]
elif name[:1] == '*':
return r'\*' + name[1:]
else:
return name

def _process_param(self, param, desc, fake_autosummary):
"""Determine how to display a parameter
Expand Down Expand Up @@ -122,7 +130,8 @@ def _process_param(self, param, desc, fake_autosummary):
complicated to incorporate autosummary's signature mangling, as it
relies on Sphinx's plugin mechanism.
"""
param = param.strip()
param = self._escape_args_and_kwargs(param.strip())
# param = param.strip()
# XXX: If changing the following, please check the rendering when param
# ends with '_', e.g. 'word_'
# See https://github.com/numpy/numpydoc/pull/144
Expand Down
26 changes: 26 additions & 0 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,32 @@ class Dummy:
assert "test attribute" in str(doc)


def test_args_and_kwargs():
cfg = dict()
doc = SphinxDocString("""
Parameters
----------
param1 : int
First parameter
*args : tuple
Arguments
**kwargs : dict
Keyword arguments
""", config=cfg)
line_by_line_compare(str(doc), """
:Parameters:
**param1** : int
First parameter
**\*args** : tuple
Arguments
**\*\*kwargs** : dict
Keyword arguments
""")


if __name__ == "__main__":
import nose
nose.run()

0 comments on commit 9cd5944

Please sign in to comment.