Python docstrings (Google style)
Mission
When editing or creating Python code, write high-quality Google-style docstrings for:
- Modules (top-of-file docstring)
- Public classes
- Public functions
- Public methods and properties
Docstrings must render well in mkdocs + mkdocs-material + mkdocstrings.
Trigger conditions
Use this skill when you:
- Add or modify a public module/class/function/method/property
- See missing, vague, outdated, or inconsistent docstrings
- Prepare code for API docs (mkdocstrings pages)
- Introduce non-obvious behavior, edge cases, or side effects
Definitions (for this repo)
- Public API: no leading underscore (e.g.,
fetch_prices, Client.get). Private/internal objects (leading underscore) are optional unless behavior is non-obvious.
- Type hints are the source of truth: do not repeat types in docstrings when type hints exist.
Authoring workflow
- Identify public objects changed/created.
- For each object, draft:
- A one-line summary (what it does)
- What matters to callers: constraints, invariants, side effects
- Add only the sections that apply (e.g., include
Raises: only when callers should care).
- Add at least one runnable
Examples: snippet for every public callable.
- Read it like a user: “Can I use this without opening the source?”
Output requirements
For every public object, add/upgrade a docstring that:
- Follows Google style
- Is clear, concrete, and non-marketing
- Does not repeat type hints
- Includes runnable
Examples: for every public callable
Google docstring structure (standard)
Include sections only when meaningful:
- Short summary (1 line)
- Optional extended summary (1–3 short paragraphs)
Args:
Returns:
Raises:
Attributes: (classes, when useful)
Examples:
Notes: (optional)
Warning: (rare)
Formatting rules
- Use triple double quotes:
"""Docstring..."""
- Summary line ends with a period.
- Wrap lines roughly ~88–100 chars when reasonable (don’t force ugly wrapping).
- Prefer imperative/active voice (“Fetch prices…”, “Validate payload…”).
- Examples must be copy-pastable (no pseudocode).
Markdown in docstrings (mkdocstrings-friendly)
- Prefer fenced code blocks with language identifiers in
Examples: (e.g., ```py).
- You may use mkdocs-material admonitions and content tabs where they add clarity.
- Avoid nesting admonitions inside each other.
- Keep function/method docstrings simple; put richer narrative/context in module/class docstrings.
Content rules
1) Keep it user-facing
Explain what it does, what matters, and any side effects (I/O, network, mutation, caching).
2) Don’t repeat types in docstrings
Describe meaning, not types. The user will see type hints.
✅ Do
Args:
ticker: Stock ticker symbol (e.g., "AAPL").
period: Time period to fetch. Defaults to "1y".
Returns:
A DataFrame containing historical stock prices.
❌ Don’t
Args:
ticker (str): ...
period (str, optional): ...
Returns:
pd.DataFrame: ...
Object-specific rules
Module docstrings
Every module should start with a module docstring that answers:
- What the module provides/contains/implements
- Typical usage
- Important constraints (timezone assumptions, caching, side effects)
Class docstrings
Class docstrings should describe:
- What the class represents/does/implements
- Lifecycle/ownership (resources, caches)
- Key invariants
- Constructor expectations (especially if non-obvious)
If the class is primarily a data container, document fields in Attributes:. Otherwise, document the public attributes that matter to callers.
Method/property docstrings
- For obvious getters/setters, keep it brief but still include an example (even a tiny one).
- Mention side effects (writes to disk, network calls, mutates internal state).
- In
Raises:, document meaningful error conditions (don’t list every low-level exception).
Examples: rules (important)
Every public callable must have Examples: with at least one runnable example.
Examples should:
- Use realistic values (
"AAPL", "1d", etc.)
- Show the most common happy path first
- Avoid network calls in examples unless the module is literally a client library
- Prefer tiny examples that won’t rot quickly
- Don’t use
>>> prompts; use standard script-style code blocks so users can copy-paste directly.
If a function is async, example must use asyncio.run(...).
Quality checklist (must pass)
1---2name: document-python-component3description: Write or upgrade conventional Python docstrings for public modules, classes, functions, methods, and properties. Docstrings must be user-facing, mkdocstrings-friendly, include runnable examples, and must not repeat type hints.4---5
6# Python docstrings (Google style)
7
8## Mission
9When editing or creating Python code, write **high-quality Google-style docstrings** for:
10- Modules (top-of-file docstring)
11- Public classes
12- Public functions
13- Public methods and properties
14
15Docstrings must render well in **mkdocs + mkdocs-material + mkdocstrings**.
16
17## Trigger conditions
18Use this skill when you:
19- Add or modify a public module/class/function/method/property
20- See missing, vague, outdated, or inconsistent docstrings
21- Prepare code for API docs (mkdocstrings pages)
22- Introduce non-obvious behavior, edge cases, or side effects
23
24## Definitions (for this repo)
25- **Public API**: no leading underscore (e.g., `fetch_prices`, `Client.get`). Private/internal objects (leading underscore) are optional unless behavior is non-obvious.
26- **Type hints are the source of truth**: do **not** repeat types in docstrings when type hints exist.
27
28## Authoring workflow
291. Identify public objects changed/created.
302. For each object, draft:
31 - A one-line summary (what it does)
32 - What matters to callers: constraints, invariants, side effects
333. Add only the sections that apply (e.g., include `Raises:` only when callers should care).
344. Add at least one runnable `Examples:` snippet for every public callable.
355. Read it like a user: “Can I use this without opening the source?”
36
37## Output requirements
38For every **public** object, add/upgrade a docstring that:
391. Follows **Google style**
402. Is **clear, concrete, and non-marketing**
413. Does **not** repeat type hints
424. Includes runnable `Examples:` for every public callable
43
44## Google docstring structure (standard)
45Include sections only when meaningful:
46- Short summary (1 line)
47- Optional extended summary (1–3 short paragraphs)
48- `Args:`
49- `Returns:`
50- `Raises:`
51- `Attributes:` (classes, when useful)
52- `Examples:`
53- `Notes:` (optional)
54- `Warning:` (rare)
55
56## Formatting rules
57- Use triple double quotes: `"""Docstring..."""`
58- Summary line ends with a period.
59- Wrap lines roughly ~88–100 chars when reasonable (don’t force ugly wrapping).
60- Prefer imperative/active voice (“Fetch prices…”, “Validate payload…”).
61- Examples must be **copy-pastable** (no pseudocode).
62
63## Markdown in docstrings (mkdocstrings-friendly)
64- Prefer fenced code blocks with language identifiers in `Examples:` (e.g., ```py).
65- You may use mkdocs-material **admonitions** and **content tabs** where they add clarity.
66- Avoid nesting admonitions inside each other.
67- Keep function/method docstrings simple; put richer narrative/context in module/class docstrings.
68
69## Content rules
70### 1) Keep it user-facing
71Explain what it does, what matters, and any side effects (I/O, network, mutation, caching).
72
73### 2) Don’t repeat types in docstrings
74Describe meaning, not types. The user will see type hints.
75
76✅ Do
77```py
78Args:
79 ticker: Stock ticker symbol (e.g., "AAPL").
80 period: Time period to fetch. Defaults to "1y".
81
82Returns:
83 A DataFrame containing historical stock prices.
84```
85
86❌ Don’t
87```py
88Args:
89 ticker (str): ...
90 period (str, optional): ...
91
92Returns:
93 pd.DataFrame: ...
94```
95
96## Object-specific rules
97### Module docstrings
98Every module should start with a module docstring that answers:
99- What the module provides/contains/implements
100- Typical usage
101- Important constraints (timezone assumptions, caching, side effects)
102
103### Class docstrings
104Class docstrings should describe:
105- What the class represents/does/implements
106- Lifecycle/ownership (resources, caches)
107- Key invariants
108- Constructor expectations (especially if non-obvious)
109
110If the class is primarily a data container, document fields in `Attributes:`. Otherwise, document the public attributes that matter to callers.
111
112### Method/property docstrings
113- For obvious getters/setters, keep it brief but still include an example (even a tiny one).
114- Mention side effects (writes to disk, network calls, mutates internal state).
115- In `Raises:`, document meaningful error conditions (don’t list every low-level exception).
116
117## `Examples:` rules (important)
118Every public callable must have `Examples:` with at least one runnable example.
119
120Examples should:
121- Use realistic values (`"AAPL"`, `"1d"`, etc.)
122- Show the most common happy path first
123- Avoid network calls in examples unless the module is literally a client library
124- Prefer tiny examples that won’t rot quickly
125- Don’t use `>>>` prompts; use standard script-style code blocks so users can copy-paste directly.
126
127If a function is async, example must use `asyncio.run(...)`.
128
129## Quality checklist (must pass)
130- [ ] Module has a top-quality docstring following software engineering best practices
131- [ ] Every public function/class/method/property has a docstring
132- [ ] Every public callable has `Examples:` with runnable code
133- [ ] Args/Attributes describe meaning but **no types**
134- [ ] Returns describes meaning (and shape if non-obvious)
135- [ ] Raises lists meaningful exceptions + when they occur
136- [ ] No fluff; no internal implementation narration unless it affects use