Multi-line description of a parameter description in python docstring
Good research effort from the Original Poster. It is a surprise that the canonical sphinx documentation does not give a multi-line example on params, despite the fact that multi-line document is inevitable due to the 79-character guideline in PEP8.
In practice, considering that your parameter name itself is typically a word
or even longer snake_case_words
, prefixed by the already lenghty <4 or 8+ spaces> :param
, it would be wise to make the next line indent for just one level (i.e. 4 spaces), which matches the "hanging indents" style metioned in
PEP 8.
class Foo(object):
def f(a, bionic_beaver, cosmic_cuttlefish):
""" Does something.
:param a: something simple
:param bionic_beaver: well, it's not something simple,
so it may require more than eighty chars,
and more, and more
:param cosmic_cuttlefish:
Or you can just put all your multi-line sentences
to start with SAME indentation.
"""
PS: You can see it in action in, for example, here. Sphinx can pick up those docstrings and generates docs without any issue.
Seems that if you indent by at least one level relative to the :param: directive, it will not break reSTructuredText rendering. Personally, I prefer to align all additional lines to the first description line of that parameter. Note, that reST will also ignore new lines and render your text without your line breaks.
Unfortunately, I could not find any source that would mention this issue or give an example of a multi-line :param: description.
simply newline where you want the line to break.
def f(a, b):
""" Does something with a and b
:param a: something simple
:param b: well, it's not something simple,
so it may require more than eighty
chars
"""