Files
orion/app/modules/contracts/base.py
Samir Boulahtit f20266167d
Some checks failed
CI / ruff (push) Failing after 7s
CI / pytest (push) Failing after 1s
CI / architecture (push) Failing after 9s
CI / dependency-scanning (push) Successful in 27s
CI / audit (push) Successful in 8s
CI / docs (push) Has been skipped
fix(lint): auto-fix ruff violations and tune lint rules
- Auto-fixed 4,496 lint issues (import sorting, modern syntax, etc.)
- Added ignore rules for patterns intentional in this codebase:
  E402 (late imports), E712 (SQLAlchemy filters), B904 (raise from),
  SIM108/SIM105/SIM117 (readability preferences)
- Added per-file ignores for tests and scripts
- Excluded broken scripts/rename_terminology.py (has curly quotes)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 23:10:42 +01:00

47 lines
1.1 KiB
Python

# app/modules/contracts/base.py
"""
Base protocol definitions for cross-module communication.
Protocols define the interface that services must implement without
requiring inheritance. This allows for:
- Duck typing with static type checking
- Easy mocking in tests
- Module independence
"""
from typing import TYPE_CHECKING, Protocol, runtime_checkable
if TYPE_CHECKING:
from sqlalchemy.orm import Session
@runtime_checkable
class ServiceProtocol(Protocol):
"""
Base protocol for all module services.
Services should be stateless and operate on database sessions
passed as arguments. This ensures:
- Thread safety
- Transaction boundaries are clear
- Easy testing with mock sessions
"""
@runtime_checkable
class CRUDServiceProtocol(Protocol):
"""
Protocol for services that provide CRUD operations.
All methods receive a database session as the first argument.
"""
def get_by_id(self, db: "Session", id: int) -> object | None:
"""Get entity by ID."""
...
def delete(self, db: "Session", id: int) -> bool:
"""Delete entity by ID. Returns True if deleted."""
...