| mode | description |
|---|---|
ask |
Document a Python file in the project, following specific conventions for style, formatting, and documentation. |
Please document the file ${file} following the conventions observed in the project.
CRITICAL: Code Preservation Policy
- NEVER remove any existing functionality from the code
- NEVER remove or delete any commented-out sections
- NEVER modify the core logic or behavior of existing functions
- Only ADD documentation, comments, and formatting improvements
- Preserve all existing code structure and implementation details
General Style:
- Add extensive inline comments to explain the logic, especially for complex parts. The goal is to make the code understandable even for a developer new to the project.
- Use section headers like
---or===to structure the code into logical blocks (e.g.,# ================================= STEP 1: Description =================================).
Import Documentation:
- Add inline comments to all imports explaining their purpose and usage in the module:
import logging # For error and debug logging import pandas as pd # Data manipulation and analysis library import io # Input/output operations (for string buffers) import traceback # For detailed error stack traces
- For custom/project-specific imports, be especially detailed about their functionality:
from tools.nexcap import NEXCAP # NEXCAP API integration from tools.google import GOOGLE # Google Drive API integration from tools.skywise import SKYWISE # Skywise platform integration
- Group imports logically and add section comments when appropriate:
# Standard library imports for various functionalities import logging import pandas as pd # Custom tool imports - these are project-specific modules from tools.nexcap import NEXCAP from tools.google import GOOGLE
Function Signature Formatting:
- Always use the following multiline format with 8-space indentation for parameters:
def extract_station_substation( address: str ) -> Tuple[str, str, str]:
- For functions with multiple parameters, maintain the same indentation pattern:
def complex_function( param1: str, param2: int, param3: Optional[Dict[str, Any]] ) -> Tuple[str, str, str]:
- Always include complete type hints for all parameters and return values
- Place the return type annotation on its own line with proper indentation
Code Formatting & Alignment:
- Align variable assignments for improved readability when declaring multiple related variables:
test = 1 somethingelse = 2 another_var = 3
- Align dictionary keys and values for better visual structure with spaces around colons:
config = { 'somevalue' : 'somekey', 'someothervalue' : 'someotherkey', 'short' : 'val' }
- For dictionary alignment, align colons to the longest key with spaces before and after the colon:
schema_properties = { "short_key" : {"type": "string"}, "much_longer_key" : {"type": "boolean"}, "medium_length_key" : {"type": "number"} }
- Apply similar alignment principles to function arguments when spanning multiple lines:
function_call( short_param = value1, longer_param = value2, very_long_param = value3 )
- Format arrays and lists in a readable multi-line structure when they contain many elements:
required_fields = [ "program_name", "program_config_id", "timeout", "is_activate", "is_val", "output_dir", "cert_path" ]
- Maintain consistent spacing and alignment in lists, tuples, and other data structures where it enhances readability.
Type Hinting Requirements:
- ALL function and method signatures MUST include complete type hints for both arguments and return values
- Use proper imports from typing module (Dict, List, Any, Optional, Tuple, etc.)
- Ensure type hints accurately reflect the actual data types being used
- For complex return types, use appropriate compound types (e.g.,
Tuple[str, str, str],Dict[str, Any]) - When functions don't return a value, explicitly use
-> None
File-Level Docstring:
- Start with a brief title for the module.
- Follow with a paragraph explaining the module's overall purpose and functionality.
- Include a "Main functionality" section with a bulleted list of key responsibilities.
Function/Method/Class Docstrings:
- Use Google-style docstrings for ALL functions, methods, and classes.
- Start with a concise, one-sentence summary.
- Provide a more detailed paragraph explaining what the function does, its purpose, and any important context.
- Document all parameters under an
Args:section, including their types and a clear description:def extract_station_substation( address: str ) -> Tuple[str, str, str]: """ Parse a hierarchical address string to extract station, substation, and capsule components. This function splits an address path and extracts the relevant hierarchical components based on the address structure convention used in the system. Args: address (str): The full hierarchical address path with forward slash separators Returns: Tuple[str, str, str]: A tuple containing (station, substation, capsule) Example: >>> extract_station_substation("/CAP1/zone/area/STATION_A/SUB_B") ("STATION_A", "SUB_B", "CAP1") """
- Document the return value under a
Returns:section, including its type and what it represents. - If applicable, include a
Side Effects:section for any external changes the function makes (e.g., file I/O, API calls). - If helpful, provide a simple
Example:of usage with actual code samples.
Inline Documentation:
- Add comprehensive inline comments throughout function bodies to explain:
- Complex logic or algorithms
- Business rules or domain-specific requirements
- Data transformations and their purpose
- Error handling strategies
- Performance considerations
- Use descriptive variable names and add comments when the purpose isn't immediately clear
- Comment any regex patterns, complex calculations, or non-obvious code constructs
- Explain the purpose of loops, conditionals, and data structure manipulations
Commented Code Preservation:
- Preserve ALL existing commented-out code sections exactly as they are
- Do NOT remove any
# TODO,# FIXME, or similar developer notes - Maintain any integration test sections or debugging code that may be commented out
- Keep all existing code structure and organization intact
add
doc-add.prompt.mdto.github/prompts/doc-add.prompt.mdadd
python.instructions.mdto.github/instructions/python.instructions.mdWhen needing to refactor old or 3rd party code, always start with:
/add-doc #<your-file>When AI generates new code, it will now always be
clean,typed, and properlydocumentedHaving documented code will make it easier for AI (and the human) to work with, since it's basically like having a full PRD associated with the code, meaning AI will not 1st have to try and guess what your code does