Ruff-Cleanup: ganzes MC2-Repo lint-grün + projekt-passende ruff.toml

Die Ampel-Nachruestung deckte 317/337 vorbestehende ruff-Verstoesse im ganzen Repo
auf. Aufgeraeumt:
- ruff.toml: intentionale Muster als Projekt-Politik ausgenommen (BLE001 blind-except,
  S110/S112 try-except-pass/continue, PLW1510 subprocess-best-effort, B008 FastAPI-
  Depends/File-Idiom, EXE001 Shebang, + wenige Stil-Regeln). __init__.py-Re-Exports
  geschuetzt (F401).
- ruff --fix: 128 mechanische (Import-Sortierung, PEP585/604-Annotationen, tote Imports,
  ueberfluessige noqa) auto-behoben.
- 12 echte Reste von Hand: PERF402/102, PLC3002 (Lambda->walrus), ISC004 (String-Concat
  geklammert), F841/RUF059 (ungenutzte Vars), PIE810 (startswith-Tuple), UP031 (f-string),
  UP035 (veraltete typing-Imports).
Ergebnis: 'ruff check .' = 0, 'compileall' grün. Kein Verhaltenswechsel (nur Stil/Modernisierung).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hitonabi
2026-07-24 20:53:36 +02:00
parent e6502f676a
commit 47f7a85510
58 changed files with 174 additions and 171 deletions
+8 -5
View File
@@ -331,7 +331,7 @@ def chatterbox_tts(text: str, language: str, ref_path: str) -> bytes:
try:
wav = model.generate(text, **kwargs)
break
except Exception as exc: # noqa: BLE001
except Exception as exc:
last_err = exc
log.warning("Chatterbox-Generation fehlgeschlagen (Versuch %d/3): %s", attempt + 1, exc)
if wav is None:
@@ -421,7 +421,7 @@ def elevenlabs_list() -> list[dict]:
for v in data.get("voices", [])
if v.get("category") != "premade"
]
except Exception: # noqa: BLE001
except Exception:
log.warning("ElevenLabs-Stimmenliste fehlgeschlagen", exc_info=True)
return []
@@ -431,6 +431,7 @@ def elevenlabs_list() -> list[dict]:
# =================================================================================
def edge_tts_synth(text: str, voice: str) -> bytes:
import asyncio
import edge_tts
v = voice or EDGE_DEFAULT
@@ -445,7 +446,7 @@ def edge_tts_synth(text: str, voice: str) -> bytes:
try:
return asyncio.run(_run())
except Exception as exc: # noqa: BLE001
except Exception as exc:
raise HTTPException(502, f"Edge-TTS-Fehler: {exc}")
@@ -459,6 +460,7 @@ def edge_list() -> list[dict]:
return _edge_cache
try:
import asyncio
import edge_tts
voices = asyncio.run(edge_tts.list_voices())
@@ -474,7 +476,7 @@ def edge_list() -> list[dict]:
"clonable": False, "_female": v.get("Gender") == "Female"})
out.sort(key=lambda i: (not i.pop("_female"), i["id"]))
_edge_cache = out
except Exception: # noqa: BLE001
except Exception:
log.warning("Edge-Stimmenliste fehlgeschlagen", exc_info=True)
_edge_cache = []
return _edge_cache
@@ -498,6 +500,7 @@ async def lifespan(_app: FastAPI):
# /turn-Aufruf kostete sonst ~3,3 s — das traf beim Realtest den ersten gesprochenen Satz.
try:
import io as _io
import numpy as _np
import soundfile as _sf
buf = _io.BytesIO()
@@ -582,7 +585,7 @@ def _save_reference_as_wav(data: bytes, filename: str) -> str:
dest = REFS_DIR / "ref.wav"
import soundfile as sf
try:
from faster_whisper.audio import decode_audio # PyAV-basiert, kann mp3/m4a/ogg/wav
from faster_whisper.audio import decode_audio # PyAV-basiert, kann mp3/m4a/ogg/wav
arr = decode_audio(str(raw), sampling_rate=24000)
sf.write(str(dest), arr, 24000, subtype="PCM_16")
return str(dest)