Python Code Style¶
Type Hints¶
- All functions must have type hints
- Use
from __future__ import annotationsfor forward references - Use
TYPE_CHECKINGblock for import-only types
Imports¶
- Imports at top of file, never inline (except in functions to avoid circular imports)
- Use lazy imports in CLI commands for faster startup
- Order: stdlib, third-party, local
Error Handling¶
- Use specific exception types
- Chain exceptions with
raise ... from errorraise ... from None - Log errors before re-raising when appropriate
Naming¶
- snake_case for functions and variables
- PascalCase for classes
- UPPER_CASE for constants
- Prefix private methods with underscore
Docstrings¶
- Use Google-style docstrings
- Document Args, Returns, Raises
- Keep docstrings concise but complete