package documentation

Pydoctor pre-process Google-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 Google style docstrings.

This module demonstrates documentation as specified by the Google Python Style Guide. Docstrings may extend over multiple lines. Sections are created with a section header and a colon followed by a block of indented text.

Example

Examples can be given using either the Example or Examples sections. Sections support any reStructuredText formatting, including literal blocks:

$ python example_google.py

Section breaks are created by resuming unindented text. Section breaks are also implicitly created anytime a new section starts.

From __init__.py:

Class ExampleClass The summary line for a class docstring should fit on one line.
Class ExamplePEP526Class The summary line for a class docstring should fit on one line.
Exception ExampleError Exceptions are documented in the same way as classes.
Function example_generator Generators have a Yields section instead of a Returns section.
Function function_with_pep484_type_annotations Example function with PEP 484 type annotations.
Function function_with_types_in_docstring Example function with types documented in the docstring.
Function module_level_function This is an example of a module level function.
Instance Variable module_level_variable1 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_level_variable2 Module level variable documented inline.
module_level_variable1: int = (source)

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.

module_level_variable2: int = (source)

Module level variable documented inline.

The docstring may span multiple lines. The type may optionally be specified on the first line, separated by a colon.

def function_with_types_in_docstring(param1, param2): (source)

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:intThe first parameter.
param2:strThe second parameter.
Returns
boolThe return value. True for success, False otherwise.
def function_with_pep484_type_annotations(param1: int, param2: str) -> bool: (source)

Example function with PEP 484 type annotations.

Parameters
param1:intThe first parameter.
param2:strThe second parameter.
Returns
boolThe return value. True for success, False otherwise.
def module_level_function(param1, param2=None, *args, **kwargs): (source)

This is an example of a module level function.

Function parameters should be documented in the Args 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. The "(type)" is optional.

    Multiple paragraphs are supported in parameter
    descriptions.
Parameters
param1:intThe first parameter.
param2:str, optionalThe second parameter. Defaults to None. Second line of description should be indented.
*argsVariable length argument list.
**kwargsArbitrary keyword arguments.
Returns
bool

True if successful, False otherwise.

The return type is optional and may be specified at the beginning of the Returns section followed by a colon.

The Returns section may span multiple lines and paragraphs. Following lines should be indented to match the first line.

The Returns section supports any reStructuredText formatting, including literal blocks:

{
    'param1': param1,
    'param2': param2
}
Raises
AttributeErrorThe Raises section is a list of all exceptions that are relevant to the interface.
ValueErrorIf param2 is equal to param1.
def example_generator(n): (source)

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:intThe upper limit of the range to generate, from 0 to n - 1.
Yields
intThe next number in the range of 0 to n - 1.