Search code examples
pythondocstring

How should I group similar exceptions in a docstring?


I don't see it mentioned in any style guide. Should I combine similar exception types or split them into separate lines:

"""
This is a Google style docs.
...
...
Raises:
    TypeError: foo() missing 1 required positional argument. Key must be a numeric value.
    KeyError: bar
"""

or this:

"""
This is a Google style docs.
...
...
Raises:
    TypeError: foo() missing 1 required positional argument
    TypeError: key must be a numeric value
    KeyError: bar
"""

Solution

  • I think go with second.

    """
    This is a Google style docs.
    ...
    ...
    Raises:
        TypeError: 1. foo() missing 1 required positional argument.
                   2. key must be a numeric value.
                   3. ...
        KeyError:  1. bar key is missing.
                   2. ...
    """