rules:
name: SOLID principles rule: Follow SOLID principles in all Python code. Classes should have a single responsibility. Code should be open to extension but closed to modification. Subclasses must be usable without breaking behavior. Interfaces should be minimal. High-level code must depend on abstractions, not implementations.
name: DRY (Don't Repeat Yourself) rule: Do not repeat logic or values. Reuse existing functions, constants, or utilities. Extract common logic into helpers.
name: KISS (Keep It Simple, Stupid) rule: Keep code simple and readable. Avoid overengineering or complex abstractions unless justified. Use early returns and straightforward control flow.
name: High-quality Python code
rule: Follow PEP8 for naming, indentation, and structure. Use snake_case
for variables/functions and PascalCase
for classes. Organize code into modules by concern, and avoid large monolithic files or god classes.
name: Full type hints
rule: Annotate every function and method with complete parameter and return type hints. Use Optional
, Literal
, and TypedDict
where needed. Validate with mypy
or equivalent.
name: Use dataclasses for simple data
rule: When creating plain data containers, prefer @dataclass
over manual init methods. Use frozen=True
for immutability when applicable.
name: Logging instead of print
rule: Never use print()
for runtime output. Use the logging
module with appropriate levels (info
, warning
, error
, etc.) and contextual metadata.
name: Testing with pytest
rule: All business logic must be covered by unit tests written in pytest
. Use test_*.py
naming, parameterize repetitive cases, and mock external calls.
name: Composition over inheritance rule: Favor composition over inheritance unless inheritance simplifies the model clearly. Abstract reusable behaviors into helper classes or mixins.
name: Configuration best practices
rule: Do not hardcode config values. Use .env
files, environment variables, or .toml
files and parse with python-dotenv
or tomllib
.
name: Avoid magic values
rule: Extract repeated strings, numbers, or booleans into named constants. Use Enum
for value sets and avoid inline literals.
name: Class structure and modularity rule: Classes must be small, coherent, and focused. Avoid having too many responsibilities in one class. Organize files by domain or purpose.
name: Use design patterns when appropriate rule: Apply software design patterns to improve flexibility and maintainability. Each pattern should solve a specific structural or behavioral need and be documented in the code.