Python
Purpose
Python-specific conventions for readability, correctness, maintainability.
Core Principles
- •Idiomatic Python style & stdlib practices
- •Explicitness > cleverness
- •Typing & tests reduce regressions
Rules
Style
- •PEP 8 naming & formatting
- •Use
blackor project formatter if specified - •Small, focused functions
Types & Errors
- •Type hints for public APIs & complex functions
- •Exceptions for exceptional conditions, not control flow
- •Prefer
pathlibover string paths
Structure
- •Group imports: stdlib → third-party → local
- •Avoid mutable default arguments
Examples
✅ "Use pathlib.Path & type hints for file utilities"
❌ "Use global state & implicit side effects"
Edge Cases
- •Performance hotspots: measure before optimizing
- •Legacy code: prioritize consistency w/ existing patterns
See COMMON.md.