refactor: enforce BasedPyright strict type checking (#5158)
This commit is contained in:
@@ -10,7 +10,7 @@ import time
|
||||
import uuid
|
||||
from contextlib import suppress
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from filelock import FileLock
|
||||
from loguru import logger
|
||||
@@ -204,7 +204,7 @@ class LocalTriggerStore:
|
||||
logger.exception("Trigger: failed to parse delivery {}", path)
|
||||
self._move_bad_delivery_unlocked(path)
|
||||
continue
|
||||
os.replace(path, delivery.path)
|
||||
os.replace(path, cast(Path, delivery.path))
|
||||
claimed.append(delivery)
|
||||
return claimed
|
||||
|
||||
@@ -311,9 +311,11 @@ class LocalTriggerStore:
|
||||
return []
|
||||
try:
|
||||
data = json.loads(self.store_path.read_text(encoding="utf-8"))
|
||||
store_data = cast(dict[str, Any], data)
|
||||
raw_triggers = cast(list[Any], store_data.get("triggers", []))
|
||||
return [
|
||||
LocalTrigger.from_dict(raw)
|
||||
for raw in data.get("triggers", [])
|
||||
LocalTrigger.from_dict(cast(dict[str, Any], raw))
|
||||
for raw in raw_triggers
|
||||
if isinstance(raw, dict)
|
||||
]
|
||||
except Exception as exc:
|
||||
@@ -386,10 +388,12 @@ class LocalTriggerStore:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
return None
|
||||
raw = data.get("delivery", data) if isinstance(data, dict) else None
|
||||
payload = cast(dict[str, Any], data) if isinstance(data, dict) else None
|
||||
raw = payload.get("delivery", payload) if payload is not None else None
|
||||
if not isinstance(raw, dict):
|
||||
return None
|
||||
trigger_id = raw.get("triggerId", raw.get("trigger_id", ""))
|
||||
delivery_data = cast(dict[str, Any], raw)
|
||||
trigger_id = delivery_data.get("triggerId", delivery_data.get("trigger_id", ""))
|
||||
return str(trigger_id) if trigger_id else None
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any, Literal
|
||||
from typing import Any, Literal, cast
|
||||
|
||||
from nanobot.utils.dict_keys import get_camel_snake as _get
|
||||
|
||||
@@ -68,9 +68,14 @@ class LocalTrigger:
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "LocalTrigger":
|
||||
raw_history = data.get("runHistory", data.get("run_history", [])) or []
|
||||
history = [
|
||||
record if isinstance(record, TriggerRunRecord) else TriggerRunRecord.from_dict(record)
|
||||
raw_history = cast(
|
||||
list[Any],
|
||||
data.get("runHistory", data.get("run_history", [])) or [],
|
||||
)
|
||||
history: list[TriggerRunRecord] = [
|
||||
record
|
||||
if isinstance(record, TriggerRunRecord)
|
||||
else TriggerRunRecord.from_dict(cast(dict[str, Any], record))
|
||||
for record in raw_history
|
||||
if isinstance(record, (dict, TriggerRunRecord))
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user