ci/lint: replace dead type:ignore with casts and clean async gen

Drop ignored # type: ignore comments (basedpyright skips them); type
tomlkit tables via cast; empty stream without reportUnreachable.
This commit is contained in:
2026-07-14 18:08:22 +08:00
parent b72a9a8c1c
commit 770e239d27
2 changed files with 21 additions and 20 deletions
+18 -17
View File
@@ -9,7 +9,7 @@ import tomlkit
from .models import DatabaseConfig, Provider from .models import DatabaseConfig, Provider
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Mapping from collections.abc import Mapping, MutableMapping
from pathlib import Path from pathlib import Path
@@ -132,6 +132,12 @@ class ConfigStore:
# -- internal sync helpers -- # -- internal sync helpers --
def _toml_table(self, key: str) -> MutableMapping[str, object]:
"""Return a mutable table for ``key``, creating it if missing."""
if key not in self._document:
self._document[key] = tomlkit.table()
return cast("MutableMapping[str, object]", self._document[key])
def _sync_database_section(self) -> None: def _sync_database_section(self) -> None:
"""Sync ``[database]`` to the document.""" """Sync ``[database]`` to the document."""
raw_db: dict[str, object] = msgspec.to_builtins(self._database) raw_db: dict[str, object] = msgspec.to_builtins(self._database)
@@ -140,35 +146,30 @@ class ConfigStore:
del self._document["database"] del self._document["database"]
return return
if "database" not in self._document: section = self._toml_table("database")
self._document["database"] = tomlkit.table() for k in list(section.keys()):
section = self._document["database"]
for k in list(section.keys()): # type: ignore[union-attr]
if k not in raw_db: if k not in raw_db:
del section[k] # type: ignore[union-attr] del section[k]
for k, v in raw_db.items(): for k, v in raw_db.items():
section[k] = v # type: ignore[union-attr] section[k] = v
def _sync_providers_section(self) -> None: def _sync_providers_section(self) -> None:
"""Sync ``[providers]`` to the document.""" """Sync ``[providers]`` to the document."""
if "providers" not in self._document: section = self._toml_table("providers")
self._document["providers"] = tomlkit.table()
section = self._document["providers"]
for name in list(section.keys()): # type: ignore[union-attr] for name in list(section.keys()):
if name not in self._providers: if name not in self._providers:
del section[name] # type: ignore[union-attr] del section[name]
for name, provider in self._providers.items(): for name, provider in self._providers.items():
raw: dict[str, object] = msgspec.to_builtins(provider) raw: dict[str, object] = msgspec.to_builtins(provider)
if name in section: if name in section:
entry = section[name] # type: ignore[union-attr] entry = cast("MutableMapping[str, object]", section[name])
entry.clear() # type: ignore[union-attr] entry.clear()
for k, v in raw.items(): for k, v in raw.items():
entry[k] = v # type: ignore[union-attr] entry[k] = v
else: else:
section[name] = raw # type: ignore[union-attr] section[name] = raw
def _sync_to_document(self) -> None: def _sync_to_document(self) -> None:
"""Incrementally sync all sections into the document.""" """Incrementally sync all sections into the document."""
+3 -3
View File
@@ -63,9 +63,9 @@ class ScriptedClient:
return self._responses.pop(0) return self._responses.pop(0)
async def _empty_stream(self) -> AsyncIterator[ChatCompletionChunk]: async def _empty_stream(self) -> AsyncIterator[ChatCompletionChunk]:
if False: # pyright: ignore[reportUnreachable] empty: list[ChatCompletionChunk] = []
yield # type: ignore[misc] for chunk in empty:
return yield chunk
def _response(message: AssistantChatMessage) -> ChatCompletionResponse: def _response(message: AssistantChatMessage) -> ChatCompletionResponse: