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:
@@ -20,7 +20,10 @@ nur Schreib-Operationen.
|
||||
|
||||
Ausgabe {"action":"block","message":...} = Tool geblockt; {} = durchlassen.
|
||||
"""
|
||||
import sys, json, os, re
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def out(obj):
|
||||
|
||||
@@ -15,10 +15,10 @@ verschlucken und den Tabu-Guard lautlos deaktivieren.
|
||||
Idempotent + validiert + Backup. Anker fuer neue Event-Bloecke ist der bestehende
|
||||
`pre_verify`-Block. Arg: Pfad zur Profil-config.yaml.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
import datetime
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
try:
|
||||
import yaml
|
||||
|
||||
@@ -44,7 +44,7 @@ def main() -> int:
|
||||
try:
|
||||
coder.summarizer.max_tokens = 10 ** 9
|
||||
print(f"[driver] summarizer.max_tokens -> {coder.summarizer.max_tokens}", flush=True)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
except Exception as exc:
|
||||
print(f"[driver] WARN konnte summarizer nicht abschalten: {exc}", flush=True)
|
||||
|
||||
for i, msg in enumerate(messages, 1):
|
||||
@@ -52,7 +52,7 @@ def main() -> int:
|
||||
print(f">> {msg[:140]}", flush=True)
|
||||
try:
|
||||
coder.run(with_message=msg)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
except Exception as exc:
|
||||
print(f"[driver] TURN {i} Fehler: {exc!r}", flush=True)
|
||||
break
|
||||
sent = getattr(coder, "total_tokens_sent", "?")
|
||||
|
||||
@@ -153,7 +153,7 @@ def _post_announce(est) -> None:
|
||||
resp.read()
|
||||
conn.close()
|
||||
log(f"ANNOUNCE -> Lucy status={resp.status} est={est}")
|
||||
except Exception as exc: # noqa: BLE001
|
||||
except Exception as exc:
|
||||
log(f"ANNOUNCE fehlgeschlagen: {exc!r}")
|
||||
|
||||
|
||||
@@ -383,7 +383,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
return None
|
||||
try:
|
||||
text = tail.decode("utf-8", errors="ignore")
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
return None
|
||||
matches = _PROMPT_TOKENS_RE.findall(text)
|
||||
if not matches:
|
||||
|
||||
@@ -234,8 +234,8 @@ def main() -> int:
|
||||
continue
|
||||
n = src.count(p["old"])
|
||||
if n != 1:
|
||||
failed.append((p["name"], f"erwartete 1 Vorkommen von old, fand {n} "
|
||||
"(Update hat den Kontext geaendert?)"))
|
||||
failed.append((p["name"], (f"erwartete 1 Vorkommen von old, fand {n} "
|
||||
"(Update hat den Kontext geaendert?)")))
|
||||
continue
|
||||
f.write_text(src.replace(p["old"], p["new"]), encoding="utf-8")
|
||||
try:
|
||||
|
||||
@@ -23,7 +23,7 @@ import sys
|
||||
_TASK_RE = re.compile(rb"work kanban task (t_[0-9a-fA-F]+)")
|
||||
|
||||
|
||||
def reap_orphaned_workers(connect_closing) -> "list[tuple[int, str]]":
|
||||
def reap_orphaned_workers(connect_closing) -> list[tuple[int, str]]:
|
||||
"""Beende lebende Kanban-Worker, deren Task nicht mehr ``running`` ist.
|
||||
|
||||
``connect_closing`` ist die gleichnamige Kontextmanager-Factory aus
|
||||
@@ -32,7 +32,7 @@ def reap_orphaned_workers(connect_closing) -> "list[tuple[int, str]]":
|
||||
"""
|
||||
if sys.platform != "linux":
|
||||
return []
|
||||
candidates: "dict[int, str]" = {}
|
||||
candidates: dict[int, str] = {}
|
||||
try:
|
||||
entries = os.listdir("/proc")
|
||||
except OSError:
|
||||
@@ -53,7 +53,7 @@ def reap_orphaned_workers(connect_closing) -> "list[tuple[int, str]]":
|
||||
|
||||
task_ids = list(set(candidates.values()))
|
||||
placeholders = ",".join("?" * len(task_ids))
|
||||
running: "set[str]" = set()
|
||||
running: set[str] = set()
|
||||
try:
|
||||
with connect_closing() as conn:
|
||||
running = {
|
||||
@@ -67,7 +67,7 @@ def reap_orphaned_workers(connect_closing) -> "list[tuple[int, str]]":
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
killed: "list[tuple[int, str]]" = []
|
||||
killed: list[tuple[int, str]] = []
|
||||
for pid, task_id in candidates.items():
|
||||
if task_id in running:
|
||||
continue
|
||||
|
||||
@@ -84,7 +84,7 @@ def norm(s):
|
||||
|
||||
def code_block(text, sprache="python"):
|
||||
"""Letzten passenden Code-Block extrahieren; ohne Zaun: ganzen Text nehmen."""
|
||||
bloecke = re.findall(r"```(?:%s)?\s*\n(.*?)```" % re.escape(sprache),
|
||||
bloecke = re.findall(rf"```(?:{re.escape(sprache)})?\s*\n(.*?)```",
|
||||
text or "", re.DOTALL | re.IGNORECASE)
|
||||
if bloecke:
|
||||
return bloecke[-1]
|
||||
@@ -469,7 +469,7 @@ def suite_speed(cfg, ergebnisse):
|
||||
# Kurz-Probe: misst tg (Alltags-Turn) — 2 Läufe, erster wärmt den Cache an.
|
||||
for lauf in ("warm", "kurz"):
|
||||
t0 = time.time()
|
||||
msg, tim, err = api_chat(cfg.endpoint, cfg.model, [
|
||||
_msg, tim, err = api_chat(cfg.endpoint, cfg.model, [
|
||||
{"role": "user", "content":
|
||||
"Erkläre in drei kurzen Sätzen, was ein Mixture-of-Experts-Modell "
|
||||
"ist."}], max_tokens=200, temperature=0)
|
||||
@@ -487,7 +487,7 @@ def suite_speed(cfg, ergebnisse):
|
||||
return
|
||||
lang = LANG_BAUSTEIN * 550
|
||||
t0 = time.time()
|
||||
msg, tim, err = api_chat(cfg.endpoint, cfg.model, [
|
||||
_msg, tim, err = api_chat(cfg.endpoint, cfg.model, [
|
||||
{"role": "user", "content":
|
||||
lang + "\n\nWie oft steht sinngemäß derselbe Satz oben? Antworte in "
|
||||
"einem Satz."}], max_tokens=80, temperature=0, timeout=900)
|
||||
|
||||
Reference in New Issue
Block a user