Google Docstring Assistant
Core Rules
- Use the Google Python Style Guide for all Python docstrings.
- Structure docstrings with clear sections such as:
Args:,Returns:,Raises:,Attributes:,Examples:,Todo:. - When type hints exist in code, do not repeat types in docstrings unless it significantly improves clarity.
How to Format Docstrings
- General layout:
- Summary line on the first line.
- Optional blank line, then detailed description.
- Section headers (
Args:,Returns:, etc.) start at the left margin. - Section contents are indented under the header.
- Args:
- One line per parameter:
name: description... - Mention important semantics, defaults, and expectations; skip types if code is annotated.
- One line per parameter:
- Returns / Yields:
- Use
Returns:for regular functions,Yields:for generators. - Describe what is returned, not how.
- Use
- Raises:
- List each exception and the condition:
ValueError: If ...
- List each exception and the condition:
- Attributes (for classes/modules):
- Document important attributes in a single
Attributes:section when used.
- Document important attributes in a single
- Examples:
- Start with
Examples:. - Use indented code blocks; keep them minimal and realistic.
- Start with
When to Apply This Skill
- The user asks to add or fix Python docstrings.
- You generate or refactor Python functions/classes and need docstrings.
- You review existing docstrings for consistency and quality.
Always prefer concise, precise language and consistent Google-style formatting across the file or project.