Pass mypy on loop_claude
This commit is contained in:
@@ -43,7 +43,7 @@ def written_by_human(entry) -> bool:
|
||||
texts = [part_text(part) for part in parts(entry)]
|
||||
# {"type": "user", "message": {"content": [{"tool_use_id": "toolu_01…", "type": "tool_result", "content": "hi"}]}}
|
||||
# {"type": "user", "message": {"content": [{"type": "text", "text": "[Request interrupted by user]"}]}}
|
||||
return bool(texts) and None not in texts and not any(text.startswith("[Request interrupted") for text in texts)
|
||||
return bool(texts) and all(text is not None and not text.startswith("[Request interrupted") for text in texts)
|
||||
|
||||
|
||||
def human_text(entry) -> str | None:
|
||||
@@ -100,11 +100,11 @@ def mark_trusted(config, roots) -> tuple[dict, list[str]] | Failure:
|
||||
# A model catalog file: {"fetchedAt": 1790618085238, "catalog": {"config": {"models": [{"id": "claude-opus-5-5", "name": "Opus 5.5", ...}]}}}
|
||||
def models_in(files) -> list[tuple[str, object]]:
|
||||
"""The (id, name) of each model in the newest of the parsed catalog files."""
|
||||
newest = {}
|
||||
newest: dict = {}
|
||||
for data in files:
|
||||
if isinstance(data, dict) and isinstance(data.get("fetchedAt"), (int, float)) and data["fetchedAt"] > newest.get("fetchedAt", -1):
|
||||
newest = data
|
||||
models = newest
|
||||
models: object = newest
|
||||
for key in ("catalog", "config", "models"):
|
||||
models = models.get(key) if isinstance(models, dict) else None
|
||||
return [(entry["id"], entry.get("name", entry["id"])) for entry in models if isinstance(entry, dict) and isinstance(entry.get("id"), str)] if isinstance(models, list) else []
|
||||
|
||||
@@ -21,7 +21,7 @@ def trust(config, roots) -> None:
|
||||
updated, untrusted = marked
|
||||
if not untrusted:
|
||||
return
|
||||
if failure := replace_json(config, updated, indent=2):
|
||||
print(f"could not write {config}: {failure.reason}", file=sys.stderr)
|
||||
if unwritten := replace_json(config, updated, indent=2):
|
||||
print(f"could not write {config}: {unwritten.reason}", file=sys.stderr)
|
||||
return
|
||||
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)
|
||||
|
||||
@@ -17,7 +17,7 @@ def archive(project, path, note, paths) -> Failure | None:
|
||||
# The copy lands last, so a copy on disk always has its verdict beside it.
|
||||
if not copy.exists():
|
||||
for dest, data in ((copy.with_suffix(".verdict.md"), f"{note}\n".encode()), (copy, raw)):
|
||||
if failure := replace_file(dest, data):
|
||||
return Failure(f"could not archive the transcript: {dest}: {failure.reason}")
|
||||
if unwritten := replace_file(dest, data):
|
||||
return Failure(f"could not archive the transcript: {dest}: {unwritten.reason}")
|
||||
print(f"transcript: {copy}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import itertools
|
||||
import sys
|
||||
import time
|
||||
import typing
|
||||
@@ -9,7 +8,9 @@ T = typing.TypeVar("T")
|
||||
|
||||
|
||||
def retried(who, attempt: typing.Callable[[], T | Failure]) -> T | Stop:
|
||||
for failures in itertools.count(1):
|
||||
failures = 0
|
||||
while True:
|
||||
failures += 1
|
||||
result = attempt()
|
||||
if not isinstance(result, Failure):
|
||||
return result
|
||||
|
||||
@@ -12,7 +12,7 @@ def run_worker(root, args) -> Failure | None:
|
||||
return Failure(f"could not start claude: {failure.strerror}")
|
||||
with proc:
|
||||
done = False
|
||||
for raw in proc.stdout:
|
||||
for raw in proc.stdout or ():
|
||||
event = parse(raw) or {}
|
||||
done = done or ends_stream(event)
|
||||
for part in assistant_parts(event):
|
||||
|
||||
@@ -27,5 +27,5 @@ def replace_file(path, data) -> Failure | None:
|
||||
except OSError as failure:
|
||||
if os.path.exists(staged):
|
||||
os.remove(staged)
|
||||
return Failure(failure.strerror)
|
||||
return Failure(failure.strerror or str(failure))
|
||||
return None
|
||||
|
||||
@@ -29,8 +29,8 @@ def project_model(name, paths) -> str | Stop:
|
||||
models = read_models(saved)
|
||||
if isinstance(models, Stop):
|
||||
return models
|
||||
if chosen := models.get(name):
|
||||
return chosen
|
||||
if saved_model := models.get(name):
|
||||
return saved_model
|
||||
chosen = ask_model(name, saved, paths.model_catalog)
|
||||
if isinstance(chosen, Stop):
|
||||
return chosen
|
||||
|
||||
@@ -23,7 +23,8 @@ def read_premises(root) -> str | Stop:
|
||||
|
||||
|
||||
def sections(text) -> dict[str, list[str]]:
|
||||
blocks, fenced = [], False
|
||||
blocks: list[tuple[str | None, list[str]]] = []
|
||||
fenced = False
|
||||
for line in text.splitlines():
|
||||
fenced ^= line.startswith("```")
|
||||
if not fenced and line.startswith("## "):
|
||||
@@ -32,7 +33,7 @@ def sections(text) -> dict[str, list[str]]:
|
||||
blocks.append((None, []))
|
||||
elif blocks and line.strip():
|
||||
blocks[-1][1].append(line)
|
||||
found = {}
|
||||
found: dict[str, list[str]] = {}
|
||||
for name, body in blocks:
|
||||
if name is not None:
|
||||
found.setdefault(name, []).append("\n".join(body))
|
||||
|
||||
Reference in New Issue
Block a user