refactor: improve type coercion functions and enhance type hints across multiple files

This commit is contained in:
Abhimanyu Saharan
2026-02-09 17:43:42 +05:30
parent f5d592f61a
commit dddd1e9a7a
13 changed files with 217 additions and 64 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
from collections import defaultdict
from typing import TYPE_CHECKING
from uuid import UUID
from sqlalchemy import case, func
@@ -21,18 +22,21 @@ from app.schemas.view_models import (
BoardGroupTaskSummary,
)
if TYPE_CHECKING:
from sqlalchemy.sql.elements import ColumnElement
_STATUS_ORDER = {"in_progress": 0, "review": 1, "inbox": 2, "done": 3}
_PRIORITY_ORDER = {"high": 0, "medium": 1, "low": 2}
_RUNTIME_TYPE_REFERENCES = (UUID, AsyncSession)
def _status_weight_expr() -> object:
def _status_weight_expr() -> ColumnElement[int]:
"""Return a SQL expression that sorts task statuses by configured order."""
whens = [(col(Task.status) == key, weight) for key, weight in _STATUS_ORDER.items()]
return case(*whens, else_=99)
def _priority_weight_expr() -> object:
def _priority_weight_expr() -> ColumnElement[int]:
"""Return a SQL expression that sorts task priorities by configured order."""
whens = [
(col(Task.priority) == key, weight)