All source code, identifiers, and comments must be written in English.
- Target version: Python 3.11+
- Build backend: setuptools
- Code and comments: English only
- One responsibility per function, one module per concept
- Use
|for unions,TypeAlias,Literal,Final,TypedDict, andSelf - Annotate parameters, return types, and key variables
- Use
@dataclass(slots=True, frozen=True)for data containers - Prefer
Enumfor discrete choices - No untyped public functions
- Cognitive complexity ≤ 10
- One
returnper function (except parameter validation guards) - Guard clauses only for invalid inputs
- Keep functions ≤ 20 lines when possible
- Avoid nested conditionals (“pyramid of ifs”)
- Always use context managers (
with) - Use
Ok[T] | Errpattern for recoverable results - Raise specific exceptions for unrecoverable errors
- Avoid global exception handling except at the entry point
- Use ruff for linting, style, and complexity enforcement
- Use mypy for type checking
- Use Google-style docstrings with Args / Returns / Raises
- Clarity over cleverness — no “smart” one-liners
- Framework: pytest
- Follow AAA pattern (Arrange–Act–Assert)
- Use given-when-then naming convention: test_given_valid_input_when_process_then_returns_ok()
- Each test should focus on a single behavior
- Use fixtures for setup
- Always include both success and failure paths
- Exception checks use
pytest.raises
- Always include type hints and docstrings
- Keep functions pure and self-contained
- Prefer descriptive variable names
- Provide minimal working examples and tests
All rules are automatically verified through:
- ruff (style, imports, complexity, docstrings, comments)
- mypy (typing)
- pytest (tests)