Pydoctor pre-process Numpy-style docstrings to convert them to reStructuredText. All standard reStructuredText formatting will still works as expected.
Please see restructuredtext_demo for general reStructuredText formmating exemple.
Example NumPy style docstrings.
This module demonstrates documentation as specified by the NumPy Documentation HOWTO. Docstrings may extend over multiple lines. Sections are created with a section header followed by an underline of equal length.
Example
Examples can be given using either the Example or Examples sections. Sections support any reStructuredText formatting, including literal blocks:
$ python example_numpy.py
Section breaks are created with two blank lines. Section breaks are also implicitly created anytime a new section starts. Section bodies may be indented:
Notes
This is an example of an indented section. It's like any other section, but the body is indented to help it stand out from surrounding text.
If a section is indented, then a section break is created by resuming unindented text.
From __init__.py
:
Class |
|
The summary line for a class docstring should fit on one line. |
Exception |
|
Exceptions are documented in the same way as classes. |
Function | example |
Generators have a Yields section instead of a Returns section. |
Function | function |
Example function with PEP 484 type annotations. |
Function | function |
Example function with types documented in the docstring. |
Function | module |
This is an example of a module level function. |
Variable | module |
Module level variables may be documented in either the Attributes section of the module docstring, or in an inline docstring immediately following the variable. |
Variable | module |
Module level variable documented inline. |
Generators have a Yields section instead of a Returns section.
Examples
Examples should be written in doctest format, and should illustrate how to use the function.
>>> print([i for i in example_generator(4)]) [0, 1, 2, 3]
Parameters | |
n:int | The upper limit of the range to generate, from 0 to n - 1. |
Yields | |
int | The next number in the range of 0 to n - 1. |
Example function with types documented in the docstring.
PEP 484 type annotations are supported. If attribute, parameter, and return types are annotated according to PEP 484, they do not need to be included in the docstring:
Parameters | |
param1:int | The first parameter. |
param2:str | The second parameter. |
Returns | |
bool | True if successful, False otherwise. |
This is an example of a module level function.
Function parameters should be documented in the Parameters section. The name of each parameter is required. The type and description of each parameter is optional, but should be included if not obvious.
If *args or **kwargs are accepted, they should be listed as *args and **kwargs.
The format for a parameter is:
name : type description The description may span multiple lines. Following lines should be indented to match the first line of the description. The ": type" is optional. Multiple paragraphs are supported in parameter descriptions.
Parameters | |
param1:int | The first parameter. |
param2:str , optional | The second parameter. |
*args | Variable length argument list. |
**kwargs | Arbitrary keyword arguments. |
Returns | |
bool | True if successful, False otherwise. The return type is not optional. The Returns section may span multiple lines and paragraphs. Following lines should be indented to match the first line of the description. The Returns section supports any reStructuredText formatting, including literal blocks: { 'param1': param1, 'param2': param2 } |
Raises | |
AttributeError | The Raises section is a list of all exceptions that are relevant to the interface. |
ValueError | If param2 is equal to param1. |
Module level variables may be documented in either the Attributes section of the module docstring, or in an inline docstring immediately following the variable.
Either form is acceptable, but the two should not be mixed. Choose one convention to document module level variables and be consistent with it.