refactor: enforce BasedPyright strict type checking (#5158)
This commit is contained in:
1 parent
e703481755
commit
757ad9c764
166 files changed
+4728
-2621
No files matched your search
@@ -11,19 +11,19 @@ import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from nanobot.config.paths import get_webui_dir
|
||||
from nanobot.session.history_visibility import is_hidden_history_message
|
||||
from nanobot.session.manager import (
|
||||
_SESSION_LIST_PREVIEW_MAX_CHARS,
|
||||
_SESSION_LIST_PREVIEW_MAX_RECORDS,
|
||||
_SESSION_LIST_PREVIEW_MAX_CHARS, # pyright: ignore[reportPrivateUsage]
|
||||
_SESSION_LIST_PREVIEW_MAX_RECORDS, # pyright: ignore[reportPrivateUsage]
|
||||
Session,
|
||||
SessionManager,
|
||||
_message_preview_text,
|
||||
_metadata_title,
|
||||
_message_preview_text, # pyright: ignore[reportPrivateUsage]
|
||||
_metadata_title, # pyright: ignore[reportPrivateUsage]
|
||||
)
|
||||
from nanobot.session.model_selection import model_preset_from_metadata
|
||||
|
||||
@@ -57,7 +57,7 @@ def _reconcile_index(session_manager: SessionManager) -> tuple[list[dict[str, An
|
||||
paths = sorted(
|
||||
path
|
||||
for path in session_manager.sessions_dir.glob("*.jsonl")
|
||||
if SessionManager._session_key_from_path(path) is not None
|
||||
if SessionManager._session_key_from_path(path) is not None # pyright: ignore[reportPrivateUsage]
|
||||
)
|
||||
rows: list[dict[str, Any]] = []
|
||||
changed = existing_rows is None
|
||||
@@ -92,12 +92,18 @@ def _read_index_rows(sessions_dir: Path) -> list[dict[str, Any]] | None:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError):
|
||||
return None
|
||||
if not isinstance(data, dict) or data.get("version") != _INDEX_VERSION:
|
||||
if not isinstance(data, dict):
|
||||
return None
|
||||
rows = data.get("sessions")
|
||||
if not isinstance(rows, list) or not all(isinstance(row, dict) for row in rows):
|
||||
index_data = cast(dict[str, Any], data)
|
||||
if index_data.get("version") != _INDEX_VERSION:
|
||||
return None
|
||||
return rows
|
||||
rows = index_data.get("sessions")
|
||||
if not isinstance(rows, list):
|
||||
return None
|
||||
index_rows = cast(list[Any], rows)
|
||||
if not all(isinstance(row, dict) for row in index_rows):
|
||||
return None
|
||||
return [cast(dict[str, Any], row) for row in index_rows]
|
||||
|
||||
|
||||
def _write_index_rows(sessions_dir: Path, rows: list[dict[str, Any]]) -> None:
|
||||
@@ -272,7 +278,7 @@ def _indexed_row_for_session(session: Session, path: Path) -> dict[str, Any]:
|
||||
|
||||
|
||||
def _scan_session_row(session_manager: SessionManager, path: Path) -> dict[str, Any] | None:
|
||||
storage_key = SessionManager._session_key_from_path(path)
|
||||
storage_key = SessionManager._session_key_from_path(path) # pyright: ignore[reportPrivateUsage]
|
||||
if storage_key is None:
|
||||
return None
|
||||
try:
|
||||
@@ -345,7 +351,7 @@ def _scan_session_row(session_manager: SessionManager, path: Path) -> dict[str,
|
||||
**activity_signature,
|
||||
}
|
||||
except Exception:
|
||||
repaired = session_manager._repair(storage_key)
|
||||
repaired = session_manager._repair(storage_key) # pyright: ignore[reportPrivateUsage]
|
||||
if repaired is None:
|
||||
return None
|
||||
return _indexed_row_for_session(repaired, path)
|
||||
Reference in new issue
Block a user