I have many functions in Python of the type:
def foobar(one, two):
"""
My function.
:param int one: My one argument.
:param int two: My two argument.
:rtype: Something nice.
"""
return 100 + one + two
And I need to parse the docstring to have a dictionary something like:
{
'sdesc' : 'My function.',
'params' : [('one', 'My one argument.'), ('two', 'My two argument.')],
'rtype' : 'Something nice.'
}
I can use sphinx.util.docstrings.prepare_docstring
as follows:
>>> prepare_docstring(foobar.__doc__)
['My function.', ':param int one: My one argument.', ':param int two: My two argument.', ':rtype: Something nice.', '']
I could create my own parser, maybe using regex for params and rtype, and stuff.
But is there a better way to do it or a better approach? How sphinx.ext.autodoc
does it? Any other advice on how to parse this kind of docstrings?