How should I document lists, optionals, and yields using Google-style Sphinx? [closed]
How do I indicate types for lists, optional arguments and return types for generators on Google-style docstrings using Sphinx-Napoleon?
I've tried
List[type]
list of type
Optional[type]
type, optional
and
Yields:
type:
respectively; but all produce unsatisfactory output that is not consistent with the rest of the generated documentation. For example
Optional[type]
just gives
Optional[type]
without any link for type
.
I've tried every builtin theme and have the same issues.
How should I be documenting these elements using Google-style docstrings with Sphinx-Napoleon?
I know this is quite old, but did you take a look at this example? Particularly lines:
def __init__(self, param1, param2, param3):
"""Example of docstring on the __init__ method.
The __init__ method may be documented in either the class level
docstring, or as a docstring on the __init__ method itself.
Either form is acceptable, but the two should not be mixed. Choose one
convention to document the __init__ method and be consistent with it.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1 (str): Description of `param1`.
param2 (:obj:`int`, optional): Description of `param2`. Multiple
lines are supported.
param3 (:obj:`list` of :obj:`str`): Description of `param3`.
"""
self.attr1 = param1
self.attr2 = param2
self.attr3 = param3 #: Doc comment *inline* with attribute
#: list of str: Doc comment *before* attribute, with type specified
self.attr4 = ['attr4']
self.attr5 = None
"""str: Docstring *after* attribute, with type specified."""