Skip to content

Commit 9cd5944

Browse files
authored
Merge pull request #155 from has2k1/escape-args-kwargs
Escape the * in *args and **kwargs
2 parents 9e526a9 + 5a311f3 commit 9cd5944

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

numpydoc/docscrape_sphinx.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ def _str_returns(self, name='Returns'):
8888
out += ['']
8989
return out
9090

91+
def _escape_args_and_kwargs(self, name):
92+
if name[:2] == '**':
93+
return r'\*\*' + name[2:]
94+
elif name[:1] == '*':
95+
return r'\*' + name[1:]
96+
else:
97+
return name
98+
9199
def _process_param(self, param, desc, fake_autosummary):
92100
"""Determine how to display a parameter
93101
@@ -122,7 +130,8 @@ def _process_param(self, param, desc, fake_autosummary):
122130
complicated to incorporate autosummary's signature mangling, as it
123131
relies on Sphinx's plugin mechanism.
124132
"""
125-
param = param.strip()
133+
param = self._escape_args_and_kwargs(param.strip())
134+
# param = param.strip()
126135
# XXX: If changing the following, please check the rendering when param
127136
# ends with '_', e.g. 'word_'
128137
# See https://github.com/numpy/numpydoc/pull/144

numpydoc/tests/test_docscrape.py

+26
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,32 @@ class Dummy:
12261226
assert "test attribute" in str(doc)
12271227

12281228

1229+
def test_args_and_kwargs():
1230+
cfg = dict()
1231+
doc = SphinxDocString("""
1232+
Parameters
1233+
----------
1234+
param1 : int
1235+
First parameter
1236+
*args : tuple
1237+
Arguments
1238+
**kwargs : dict
1239+
Keyword arguments
1240+
""", config=cfg)
1241+
line_by_line_compare(str(doc), """
1242+
:Parameters:
1243+
1244+
**param1** : int
1245+
First parameter
1246+
1247+
**\*args** : tuple
1248+
Arguments
1249+
1250+
**\*\*kwargs** : dict
1251+
Keyword arguments
1252+
""")
1253+
1254+
12291255
if __name__ == "__main__":
12301256
import nose
12311257
nose.run()

0 commit comments

Comments
 (0)