refactor: improve type coercion functions and enhance type hints across multiple files
This commit is contained in:
@@ -8,7 +8,7 @@ import re
|
||||
from contextlib import suppress
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from uuid import uuid4
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoescape
|
||||
@@ -452,7 +452,7 @@ async def _gateway_agent_files_index(
|
||||
continue
|
||||
name = item.get("name")
|
||||
if isinstance(name, str) and name:
|
||||
index[name] = cast(dict[str, Any], item)
|
||||
index[name] = dict(item)
|
||||
return index
|
||||
except OpenClawGatewayError:
|
||||
pass
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -148,7 +148,7 @@ async def build_board_snapshot(session: AsyncSession, board: Board) -> BoardSnap
|
||||
select(func.count(col(Approval.id)))
|
||||
.where(col(Approval.board_id) == board.id)
|
||||
.where(col(Approval.status) == "pending"),
|
||||
),
|
||||
)
|
||||
).one(),
|
||||
)
|
||||
|
||||
|
||||
@@ -167,6 +167,9 @@ class _GatewayBackoff:
|
||||
self._delay_s = min(self._delay_s * 2.0, self._max_delay_s)
|
||||
continue
|
||||
self.reset()
|
||||
if value is None:
|
||||
msg = "Gateway retry produced no value without an error"
|
||||
raise RuntimeError(msg)
|
||||
return value
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user