Python Style Guide
Use the Python version declared in pyproject.toml. Follow PEP 8 and the project’s Black, Ruff and MyPy settings; local configuration takes precedence.
Source and interfaces
- Use snake_case for modules, functions and variables, PascalCase for classes and uppercase constants.
- Annotate public interfaces and return types. Prefer small functions, explicit exceptions and context managers.
- Use double-quoted strings where the formatter permits them, and four-space indentation. Let Black handle wrapping.
- Prefer pathlib for filesystem operations and subprocess argument lists over interpolated shell commands.
- Declare direct runtime dependencies separately from development dependencies. Never embed credentials in code or logs.
from pathlib import Path
def read_config(path: Path) -> str:
"""Read configuration as UTF-8."""
return path.read_text(encoding="utf-8")
Validation
Run the repository’s format, lint, typecheck, dependency, security and test targets. Where selected, use Black, Ruff, MyPy, Deptry, Bandit, pip-audit and pytest. Document any justified lint exceptions. Add regression tests for behavior changes and boundary cases.