- Write production-ready Python focused on readability and correctness.
- Prefer explicit, maintainable code over concise but opaque patterns.
- Keep functions focused and modules cohesive.
- Design for testability and static analysis from the start.
- Type hints are required for all public functions, methods, and constants.
- Include return types on all functions, including
Nonereturns. - Use
typingandcollections.abcabstractions appropriately. - Avoid untyped containers like bare
list/dict; parameterize types. - Use
Literal,TypedDict, andProtocolwhere they improve clarity.
- Use Google-style docstrings for public modules, classes, and functions.
- Keep docstrings concise: purpose, args, returns, raises.
- Keep docs synchronized with behavior and signatures.
- Prefer
pathlib.Pathoveros.path. - Use
dataclassesfor lightweight structured data models. - Use
pydanticfor validated external/input schemas when needed. - Avoid passing raw dictionaries across domain boundaries.
- Raise specific exception types; avoid broad
Exceptionwhere possible. - Create custom exceptions for domain-level failures.
- Add contextual detail to errors without leaking sensitive data.
- Handle recoverable errors close to their boundary.
- Use
pytestas the default test framework. - Write focused unit tests and integration tests for boundaries.
- Use fixtures to share setup and reduce duplication.
- Prefer parametrized tests for multiple scenarios.
- Keep tests deterministic and side-effect controlled.
- Use
rufffor linting and formatting compliance. - Keep code compliant with configured
ruffrules before merging. - Use
uvfor environment, dependency, and package management. - Prefer reproducible dependency constraints and lockfiles.
- Follow PEP 8 with project-specific formatter/linter settings.
- Use clear names and avoid ambiguous abbreviations.
- Keep modules small and avoid circular imports.
- Prefer
Enum/constants over magic strings. - Remove unused imports and dead code promptly.