Skip to content

Escape the * in *args and **kwargs #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()