ADR-008: Strict Type Safety¶
Status: ✅ Accepted Date: 2026-01-29 Deciders: Rodrigo Roldán
Context¶
Python allows dynamic programming without types, but type hints (PEP 484+) offer:
Bug catching during development
IDE autocomplete and refactoring
Living documentation
Better maintainability
Strictness levels in mypy:
No types: No verification
Basic: Optional types, permissive
Strict: All types required, no
Any
Decision¶
Use mypy in strict mode with complete type hints.
Configuration (pyproject.toml):
[tool.mypy]
strict = true
disallow_untyped_defs = true
disallow_any_explicit = true
disallow_any_generics = true
warn_return_any = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unreachable = true
Rules:
✅ All parameters with types
✅ All returns with types
✅ Avoid
Any(use generics or Union)✅ Type hints in variables when not inferred
❌ DO NOT use
# type: ignorewithout justification❌ DO NOT use
cast()unnecessarily
Example:
# ✅ CORRECT
def send_request(
url: str,
headers: Optional[Dict[str, str]] = None,
timeout: Optional[float] = None,
) -> Response:
...
# ❌ INCORRECT
def send_request(url, headers=None, timeout=None): # No types
...
# ❌ INCORRECT
def send_request(url: Any, headers: Any = None) -> Any: # Any abused
...
Consequences¶
Positive ✅¶
Bug prevention: Catch errors in development, not at runtime
IDE support: Autocomplete, go-to-definition, refactoring
Documentation: Types are executable documentation
Refactoring safety: Changes don’t break contracts
Onboarding: New devs understand API faster
PEP 561 compliance: Distribution of type stubs
Negative ❌¶
Verbosity: Longer code
Learning curve: Advanced type hints are complex
Maintenance: Types must be updated with code
CI time: mypy adds time to pipeline
Mitigations¶
Generics: Use
TypeVarfor flexibilityProtocols: For type-safe duck typing
Overload: For complex signatures
Documentation: Type hints guide for contributors
Type Coverage¶
Target: 100% type coverage
# Verify coverage
mypy --strict src/reqivo
Alternatives Considered¶
No types: Rejected. Loses type safety benefits.
Partial types: Rejected. Inconsistency causes confusion.
Gradual typing: Rejected. New project, start strict.
References¶
PEP 484: Type Hints
PEP 561: Distributing Type Information
mypy documentation