Code Style¶
Formatting¶
We use Ruff for formatting:
- Line length: 120 characters
- Target Python: 3.12+
- Use double quotes for strings
Linting¶
Type Hints¶
Required for public APIs:
from typing import Optional
def process_input(
prompt: str,
max_tokens: Optional[int] = None,
) -> str:
"""Process the input prompt."""
return prompt
Docstrings¶
Use Google style:
def calculate_metrics(data: dict) -> dict:
"""Calculate metrics from the provided data.
Args:
data: Input data dictionary.
Returns:
Dictionary containing calculated metrics.
Raises:
ValueError: If data is invalid.
"""
pass
Naming¶
- Functions:
snake_case - Classes:
PascalCase - Constants:
UPPER_SNAKE_CASE - Private:
_leading_underscore
Imports¶
Group imports:
# Standard library
import os
from pathlib import Path
# Third-party
import torch
from pydantic import BaseModel
# Local
from gmas.core import AgentProfile
Pre-commit¶
Hooks run automatically:
- Ruff formatting
- Ruff linting
- Type checking
Install hooks: