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?
The doc string line should begin with a capital letter and end with a period. The first line should be a short description. If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description.
As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in Example 1). They are used to document our code. We can access these docstrings using the __doc__ attribute.
A docstring is a string literal placed in the first line of a function body, as shown below.
Try: class MyClass(): # ... def my_function(self): """Docstring for my function""" print MyClass. my_function.
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."""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With