Writing clear documentation strings with RST markup
How can we clearly document what a function does? Can we provide examples? Of course we can, and we really should. In the Including descriptions and documentation recipe in Chapter 2, Statements and Syntax, and in the Better RST markup in docstrings recipes, we looked at some essential documentation techniques. Those recipes introduced ReStructuredText (RST) for module docstrings.
We'll extend those techniques to write RST for function docstrings. When we use a tool such as Sphinx, the docstrings from our function will become elegant-looking documentation that describes what our function does.
Getting ready
In the Forcing keyword-only arguments with the * separator recipe, we looked at a function that had a large number of parameters and another function that had only two parameters.
Here's a slightly different version of one of those functions, Twc()
:
>>> def Twc(T, V):
... ""...