Skip to content

Google docstrings examples

Google Python Style Guide

Handsdown API Index / Examples / Google docstrings examples

Auto-generated documentation for examples.google_docstrings module.

ClassExample

Show source in google_docstrings.py:13

Google-style class example

Attributes

  • attr1 str - Description of attr1.
  • attr2 :obj:int, optional - Description of attr2.

Signature

class ClassExample:
    ...

ClassExample().method_example

Show source in google_docstrings.py:22

Summary line.

Extended description of method.

Examples

Examples should be written in doctest format, and should illustrate how to use the function

>>> print([i for i in
... example_generator(2)])
[
    'one',
    'two',
]
>>> setup_env()
>>> func_call(
...     first_name='test',
...     last_name='test',
... )

Arguments

  • text str, optional - Description of arg1
  • *args str - Description of args
  • **kwargs str - Description of kwargs

Returns

  • int - Description of return value

Signature

def method_example(self, text: str = "hello") -> int:
    ...

function_example

Show source in google_docstrings.py:56

Summary line.

Extended description of function. You can use this function like

result = function_example(
    {
        'key': 'value',
    },
    None,
)

print result

Arguments

  • arg1 int - Description of arg1
  • arg2 str - Description of arg2
  • arg3 str, optional - Description of arg3

Returns

  • bool - Description of return value

Raises

  • AttributeError - The Raises section is a list of all exceptions that are relevant to the interface.
  • ValueError - If param2 is equal to param1.

Signature

def function_example(arg1, arg2, arg3=None):
    ...

function_with_pep484_type_annotations

Show source in google_docstrings.py:87

Example function with PEP 484 type annotations.

Arguments

  • param1 - The first parameter.
  • param2 - The second parameter.

Returns

The return value. True for success, False otherwise.

Signature

def function_with_pep484_type_annotations(param1: int, param2: str) -> bool:
    ...