Module

autodoc.docstring_parser

Docstring parsers for different styles.

Supports:

  • Google style (Args:, Returns:, Raises:, Example:)
  • NumPy style (Parameters, Returns, Raises, Examples with --------)
  • Sphinx style (:param name:, :returns:, :raises:)

Classes

ParsedDocstring
Container for parsed docstring data.
2

Container for parsed docstring data.

Methods 1

to_dict
Convert to dictionary.
0 dict[str, Any]
def to_dict(self) -> dict[str, Any]

Convert to dictionary.

Returns

dict[str, Any]

Internal Methods 1
__init__
0 None
def __init__(self) -> None
GoogleDocstringParser
Parse Google-style docstrings.
7

Parse Google-style docstrings.

Methods 1

parse
Parse Google-style docstring.
1 ParsedDocstring
def parse(self, docstring: str) -> ParsedDocstring

Parse Google-style docstring.

Parameters 1
docstring str
Returns

ParsedDocstring

Internal Methods 6
_split_sections
Split docstring into sections.
1 dict[str, str]
def _split_sections(self, docstring: str) -> dict[str, str]

Split docstring into sections.

Parameters 1
docstring str
Returns

dict[str, str]

_parse_args_section
Parse Args section. Format: name (type): description name: description
1 dict[str, str]
def _parse_args_section(self, section: str) -> dict[str, str]

Parse Args section.

Format:

name (type): description
name: description
Parameters 1
section str
Returns

dict[str, str]

_parse_raises_section
Parse Raises section. Format: ExceptionType: description
1 list[dict[str, str]]
def _parse_raises_section(self, section: str) -> list[dict[str, str]]

Parse Raises section.

Format:

ExceptionType: description
Parameters 1
section str
Returns

list[dict[str, str]]

_parse_examples_section
Extract code examples.
1 list[str]
def _parse_examples_section(self, section: str) -> list[str]

Extract code examples.

Parameters 1
section str
Returns

list[str]

_parse_see_also_section
Extract cross-references.
1 list[str]
def _parse_see_also_section(self, section: str) -> list[str]

Extract cross-references.

Parameters 1
section str
Returns

list[str]

_parse_note_section
Extract notes or warnings.
1 list[str]
def _parse_note_section(self, section: str) -> list[str]

Extract notes or warnings.

Parameters 1
section str
Returns

list[str]

NumpyDocstringParser
Parse NumPy-style docstrings.
7

Parse NumPy-style docstrings.

Methods 1

parse
Parse NumPy-style docstring.
1 ParsedDocstring
def parse(self, docstring: str) -> ParsedDocstring

Parse NumPy-style docstring.

Parameters 1
docstring str
Returns

ParsedDocstring

Internal Methods 6
_split_sections
Split NumPy docstring into sections.
1 dict[str, str]
def _split_sections(self, docstring: str) -> dict[str, str]

Split NumPy docstring into sections.

Parameters 1
docstring str
Returns

dict[str, str]

_parse_parameters_section
Parse Parameters section. Format: name : type description
1 dict[str, str]
def _parse_parameters_section(self, section: str) -> dict[str, str]

Parse Parameters section.

Format:

name : type
    description
Parameters 1
section str
Returns

dict[str, str]

_parse_raises_section
Parse Raises section (similar to Parameters).
1 list[dict[str, str]]
def _parse_raises_section(self, section: str) -> list[dict[str, str]]

Parse Raises section (similar to Parameters).

Parameters 1
section str
Returns

list[dict[str, str]]

_parse_examples_section
Extract examples (usually code blocks).
1 list[str]
def _parse_examples_section(self, section: str) -> list[str]

Extract examples (usually code blocks).

Parameters 1
section str
Returns

list[str]

_parse_see_also_section
Extract cross-references.
1 list[str]
def _parse_see_also_section(self, section: str) -> list[str]

Extract cross-references.

Parameters 1
section str
Returns

list[str]

_parse_note_section
Extract notes.
1 list[str]
def _parse_note_section(self, section: str) -> list[str]

Extract notes.

Parameters 1
section str
Returns

list[str]

SphinxDocstringParser
Parse Sphinx-style docstrings.
1

Parse Sphinx-style docstrings.

Methods 1

parse
Parse Sphinx-style docstring.
1 ParsedDocstring
def parse(self, docstring: str) -> ParsedDocstring

Parse Sphinx-style docstring.

Parameters 1
docstring str
Returns

ParsedDocstring

Functions

parse_docstring
Parse docstring and extract structured information.
2 ParsedDocstring
def parse_docstring(docstring: str | None, style: str = 'auto') -> ParsedDocstring

Parse docstring and extract structured information.

Parameters 2

Name Type Default Description
docstring str | None

Raw docstring text

style str 'auto'

Docstring style ('auto', 'google', 'numpy', 'sphinx')

Returns

ParsedDocstring

ParsedDocstring object with extracted information

detect_docstring_style
Auto-detect docstring style.
1 str
def detect_docstring_style(docstring: str) -> str

Auto-detect docstring style.

Parameters 1

Name Type Default Description
docstring str

Raw docstring text

Returns

str

Style name ('google', 'numpy', 'sphinx', or 'plain')