diff --git a/numpydoc/docscrape_sphinx.py b/numpydoc/docscrape_sphinx.py index 8031aabd..257a61e4 100644 --- a/numpydoc/docscrape_sphinx.py +++ b/numpydoc/docscrape_sphinx.py @@ -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 @@ -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 diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index 7b207abd..227ee643 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -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()