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

@@ -6,7 +6,7 @@ import asyncio
import logging
import datetime
import shutil
from typing import Dict, Set
from typing import Any, Awaitable, Dict, Set, cast
from ..config import config
from ..services.service_registry import ServiceRegistry
@@ -68,7 +68,7 @@ class UsageStats:
return
# Initialize stats storage
self.stats = {
self.stats: Dict[str, Any] = {
"checkpoints": {}, # sha256 -> { total: count, history: { date: count } }
"loras": {}, # sha256 -> { total: count, history: { date: count } }
"embeddings": {}, # sha256 -> { total: count, history: { date: count } }
@@ -297,8 +297,8 @@ class UsageStats:
# Process each prompt_id
try:
registry = MetadataRegistry()
except NameError:
registry = MetadataRegistry() # pyright: ignore[reportPossiblyUnboundVariable]
except (ImportError, NameError):
# MetadataRegistry not available (standalone mode)
registry = None
@@ -374,7 +374,7 @@ class UsageStats:
if not callable(get_cached_data):
return None
cache = await get_cached_data()
cache = await cast(Awaitable[Any], get_cached_data())
raw_data = getattr(cache, "raw_data", None)
if not isinstance(raw_data, list):
return None
@@ -404,7 +404,7 @@ class UsageStats:
if not callable(get_model_roots):
return None
roots = [root for root in get_model_roots() if root]
roots = [root for root in cast(Any, get_model_roots()) if root]
if not roots:
return None
@@ -486,7 +486,7 @@ class UsageStats:
model_filename,
file_path,
)
calculated_hash = await calculate_hash(file_path)
calculated_hash = await cast(Awaitable[Any], calculate_hash(file_path))
if calculated_hash:
return calculated_hash
@@ -557,7 +557,7 @@ class UsageStats:
logger.error(f"Error processing LoRA usage: {e}", exc_info=True)
@staticmethod
def _extract_embedding_names(prompt_text: str) -> set:
def _extract_embedding_names(prompt_text: str) -> set[str]:
"""Parse embedding:name references from prompt text.
ComfyUI's SDTokenizer resolves ``embedding:<name>`` during tokenization
@@ -605,7 +605,7 @@ class UsageStats:
except Exception as e:
logger.error("Error processing embedding usage: %s", e, exc_info=True)
async def get_stats(self):
async def get_stats(self) -> Dict[str, Any]:
"""Get current usage statistics"""
return self.stats
@@ -633,7 +633,7 @@ class UsageStats:
try:
# Process metadata for this prompt_id
registry = MetadataRegistry()
registry = MetadataRegistry() # pyright: ignore[reportPossiblyUnboundVariable]
metadata = registry.get_metadata(prompt_id)
if metadata:
await self._process_metadata(metadata)