Testing on Other
Many of the functions below have been taken from the napolean sphinx extension documentation.
function_with_types_in_docstring
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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| param1 | int | The first parameter. |
| param2 | str | The second parameter. |
Returns
| TYPE | DESCRIPTION |
|---|---|
| bool | True if successful, False otherwise. .. _PEP 484: https://www.python.org/dev/peps/pep-0484/ |
function_with_pep484_type_annotations
Example function with PEP 484 type annotations.
The return type must be duplicated in the docstring to comply with the NumPy docstring style.
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| param1 | The first parameter. | |
| param2 | The second parameter. |
Returns
| TYPE | DESCRIPTION |
|---|---|
| bool | True if successful, False otherwise. |
module_level_function
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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| param1 | int | The first parameter. |
| param2 | :obj:str, optional | The second parameter. |
| *args | Variable length argument list. | |
| **kwargs | Arbitrary keyword arguments. |
Returns
| TYPE | DESCRIPTION |
|---|---|
| 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.
example_generator
Generators have a Yields section instead of a Returns section.
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| n | int | The upper limit of the range to generate, from 0 to n - 1. |
Yields
| TYPE | DESCRIPTION |
|---|---|
| int | The next number in the range of 0 to n - 1. |
Examples
Examples should be written in doctest format, and should illustrate how to use the function.
ExampleError
Exceptions are documented in the same way as classes.
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 Parameters section.
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| msg | str | Human readable string describing the exception. |
| code | :obj:int, optional | Numeric error code. |
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| msg | str | Human readable string describing the exception. |
| code | int | Numeric error code. |
ExampleClass
The summary line for a class docstring should fit on one line.
If the class has public attributes, they may be documented here in an Attributes section and follow the same formatting as a function's Args section. Alternatively, attributes may be documented inline with the attribute's declaration (see init method below).
Properties created with the @property decorator should be documented in the property's getter method.
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| attr1 | str | Description of attr1. |
| attr2 | :obj:int, optional | Description of attr2. |