Docstring parser
docstring_parser
Structured docstring parser for axm-ast.
Parses raw docstring strings into structured sections without requiring external dependencies. Supports Google, NumPy, and Sphinx styles.
Only non-redundant sections are extracted:
summary— first paragraph (unique value vs signature)raises— exception types + descriptions (absent from signature)examples— usage examples (pedagogical, not in signature)
Args and Returns are intentionally skipped: the information
they contain is already present in the function signature field.
Example
from axm_ast.docstring_parser import parse_docstring parsed = parse_docstring('Do thing.\n\nRaises:\n ValueError: bad.') parsed.summary 'Do thing.' parsed.raises [('ValueError', 'bad.')]
ParsedDocstring
dataclass
Structured representation of a parsed docstring.
Attributes:
| Name | Type | Description |
|---|---|---|
summary |
str | None
|
First paragraph of the docstring (may be multi-line). |
raises |
list[tuple[str, str]]
|
List of (exception_type, description) tuples. |
examples |
list[str]
|
List of example blocks as raw strings. |
Source code in packages/axm-ast/src/axm_ast/docstring_parser.py
parse_docstring(raw)
Parse a raw docstring string into structured sections.
Supports Google, NumPy, and Sphinx docstring styles.
Args/Returns sections are deliberately ignored (redundant
with the function signature field).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
str | None
|
Raw docstring content, or |
required |
Returns:
| Type | Description |
|---|---|
ParsedDocstring
|
|
Example
p = parse_docstring('Summary.\n\nRaises:\n ValueError: bad input.') p.summary 'Summary.' p.raises [('ValueError', 'bad input.')]