fix(types): resolve pre-existing basedpyright errors in py/ and standalone.py

Fix ~950 basedpyright errors across the backend:
- Convert ineffective # type: ignore comments to # pyright: ignore[rule]
- Add missing generic type arguments (Dict[str, Any], list[Any], ...)
- Annotate dynamic dict literals and runtime-initialized attributes
- Widen CivitAI provider tuple signatures in recipe parsers
- Remove dead LoraRoutes handlers calling nonexistent LoraService methods
- Suppress unavoidable ServiceRegistry import cycles (basedpyright counts
  function-local imports as cycle edges)
This commit is contained in:
Will Miao
2026-08-08 20:12:52 +08:00
parent 6fcdeb799d
commit 8e724538bd
103 changed files with 1184 additions and 1015 deletions

View File

@@ -12,6 +12,7 @@ from threading import Lock
from typing import (
Any,
Awaitable,
Coroutine,
Dict,
Iterable,
List,
@@ -411,7 +412,12 @@ class SettingsManager:
needs_library_bootstrap = not isinstance(libraries, dict) or not libraries
if not needs_library_bootstrap and top_level_has_paths and len(libraries) == 1:
if (
not needs_library_bootstrap
and top_level_has_paths
and isinstance(libraries, Mapping)
and len(libraries) == 1
):
only_library_payload = next(iter(libraries.values()))
if isinstance(only_library_payload, Mapping):
folder_payload = only_library_payload.get("folder_paths")
@@ -455,6 +461,9 @@ class SettingsManager:
):
seed_library_name = target_name
if not isinstance(libraries, dict) or not libraries:
return
sanitized_libraries: Dict[str, Dict[str, Any]] = {}
changed = False
for name, data in libraries.items():
@@ -594,7 +603,7 @@ class SettingsManager:
return payload
def _normalize_folder_paths(
self, folder_paths: Mapping[str, Iterable[str]]
self, folder_paths: Mapping[str, Any]
) -> Dict[str, List[str]]:
normalized: Dict[str, List[str]] = {}
for key, values in folder_paths.items():
@@ -623,7 +632,7 @@ class SettingsManager:
candidate_values = [values]
else:
try:
candidate_values = list(values) # type: ignore[arg-type]
candidate_values = list(values) # pyright: ignore[reportArgumentType]
except TypeError:
continue
@@ -656,7 +665,7 @@ class SettingsManager:
def _validate_folder_paths(
self,
library_name: str,
folder_paths: Mapping[str, Iterable[str]],
folder_paths: Mapping[str, Any],
) -> None:
"""Ensure folder paths do not overlap with other libraries.
@@ -1119,7 +1128,7 @@ class SettingsManager:
return []
if isinstance(value, str):
candidates: Iterable[str] = (
candidates: Iterable[Any] = (
value.replace("\n", ",").replace(";", ",").split(",")
)
elif isinstance(value, Sequence) and not isinstance(
@@ -1167,7 +1176,7 @@ class SettingsManager:
return []
if isinstance(value, str):
candidates: Iterable[str] = (
candidates: Iterable[Any] = (
value.replace("\n", ",").replace(";", ",").split(",")
)
elif isinstance(value, Sequence) and not isinstance(
@@ -1207,7 +1216,7 @@ class SettingsManager:
return []
if isinstance(value, str):
candidates: Iterable[str] = (
candidates: Iterable[Any] = (
value.replace("\n", ",").replace(";", ",").split(",")
)
elif isinstance(value, Sequence) and not isinstance(
@@ -1595,11 +1604,11 @@ class SettingsManager:
if key == "folder_paths" and isinstance(value, Mapping):
active_name = self.get_active_library_name()
self._validate_folder_paths(active_name, value)
self._update_active_library_entry(folder_paths=value) # type: ignore[arg-type]
self._update_active_library_entry(folder_paths=value) # pyright: ignore[reportArgumentType]
elif key == "extra_folder_paths" and isinstance(value, Mapping):
active_name = self.get_active_library_name()
self._validate_folder_paths(active_name, value)
self._update_active_library_entry(extra_folder_paths=value) # type: ignore[arg-type]
self._update_active_library_entry(extra_folder_paths=value) # pyright: ignore[reportArgumentType]
elif key == "default_lora_root":
self._update_active_library_entry(default_lora_root=str(value))
elif key == "default_checkpoint_root":
@@ -1752,12 +1761,12 @@ class SettingsManager:
"""Trigger cache resorting when the model name display preference updates."""
try:
from .service_registry import ServiceRegistry # type: ignore
from .service_registry import ServiceRegistry # pyright: ignore[reportImportCycles]
except Exception: # pragma: no cover - registry optional in some contexts
return
display_mode = value if isinstance(value, str) else "model_name"
pending: List[Tuple[Optional[asyncio.AbstractEventLoop], Awaitable[Any]]] = []
pending: List[Tuple[Optional[asyncio.AbstractEventLoop], Coroutine[Any, Any, Any]]] = []
def _resolve_service_loop(service: Any) -> Optional[asyncio.AbstractEventLoop]:
loop = getattr(service, "loop", None)
@@ -2118,7 +2127,7 @@ class SettingsManager:
logger.debug("Failed to apply library settings to config: %s", exc)
try:
from .service_registry import ServiceRegistry # type: ignore
from .service_registry import ServiceRegistry # pyright: ignore[reportImportCycles]
for service_name in (
"lora_scanner",