Code Standards
Conventions for contributing code.
Naming
- Variables/functions:
snake_case - Classes:
PascalCase - Constants:
ALL_CAPS - Files:
snake_case.py - Private members:
_prefixed
Type Hints
Required for all functions:
python
def cleanup_volumes(
session: Session,
region: str,
reporter: Reporter,
dry_run: bool = True
) -> None:
"""Delete volumes."""
passUse modern syntax:
list[str]notList[str]dict[str, Any]notDict[str, Any]str | NonenotOptional[str]
Docstrings
Required for all public functions (Google style):
python
def catalog_volumes(session: Session, region: str, reporter: Reporter) -> list[str]:
"""
List all EBS volumes in a region.
Args:
session: Boto3 session for AWS credentials.
region: AWS region name.
reporter: Event reporter instance.
Returns:
List of volume IDs.
"""
passImports
Order (enforced by ruff):
- Standard library
- Third-party (boto3, typer, rich)
- Local (
from costcutter...)
Error Handling
- Catch specific exceptions:
ClientError,ValueError - Never use bare
except: - Log errors:
logger.error(...) - Report failures:
reporter.record(..., status="failed")
Formatting
bash
# Auto-format
mise run fmt
# Check linting
mise run lintQuality Checks
Before submitting:
bash
mise run fmt # Format
mise run lint # Lint
mise run test # TestAll must pass.
Next Steps
- Testing Guide : Write tests
- Submission Guidelines : Submit PR