Annotate the return type of every function in loop_claude
This commit is contained in:
@@ -3,14 +3,14 @@ import subprocess
|
||||
from loop_claude.outcome import Stop
|
||||
|
||||
|
||||
def checkout_root(cwd):
|
||||
def checkout_root(cwd) -> str | Stop:
|
||||
found = subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True, cwd=cwd, text=True)
|
||||
if found.returncode != 0:
|
||||
return Stop(1, found.stderr.strip())
|
||||
return found.stdout.strip()
|
||||
|
||||
|
||||
def checkouts(root):
|
||||
def checkouts(root) -> list[str]:
|
||||
found = [root]
|
||||
listing = subprocess.run(["git", "worktree", "list", "--porcelain"], capture_output=True, cwd=root, text=True)
|
||||
if listing.returncode == 0:
|
||||
@@ -18,5 +18,5 @@ def checkouts(root):
|
||||
return sorted(set(found))
|
||||
|
||||
|
||||
def project_name(root, code):
|
||||
def project_name(root, code) -> str:
|
||||
return root.removeprefix(f"{code}/").lstrip("/")
|
||||
|
||||
@@ -14,7 +14,7 @@ class Models:
|
||||
worker: str
|
||||
|
||||
|
||||
def project_models(project, paths, env):
|
||||
def project_models(project, paths, env) -> Models | Stop:
|
||||
judge, worker = env.get("LOOP_CLAUDE_JUDGE_MODEL"), env.get("LOOP_CLAUDE_WORKER_MODEL")
|
||||
if judge and worker:
|
||||
return Models(judge, worker)
|
||||
@@ -24,7 +24,7 @@ def project_models(project, paths, env):
|
||||
return Models(judge or chosen, worker or chosen)
|
||||
|
||||
|
||||
def project_model(name, paths):
|
||||
def project_model(name, paths) -> str | Stop:
|
||||
saved = paths.models_file
|
||||
models = read_models(saved)
|
||||
if isinstance(models, Stop):
|
||||
@@ -44,7 +44,7 @@ def project_model(name, paths):
|
||||
return chosen
|
||||
|
||||
|
||||
def read_models(saved):
|
||||
def read_models(saved) -> dict[str, str] | Stop:
|
||||
try:
|
||||
with open(saved, encoding="utf-8") as handle:
|
||||
models = json.load(handle)
|
||||
@@ -57,7 +57,7 @@ def read_models(saved):
|
||||
return models
|
||||
|
||||
|
||||
def ask_model(name, saved, folder):
|
||||
def ask_model(name, saved, folder) -> str | Stop:
|
||||
if stop := human_needed.off_terminal(f"pick {name}'s model, or merge {{\"{name}\": \"<model>\"}} into {saved}"):
|
||||
return stop
|
||||
offered = offered_models(folder)
|
||||
|
||||
@@ -3,7 +3,7 @@ import pathlib
|
||||
from loop_claude.outcome import Stop
|
||||
|
||||
|
||||
def read_premises(root):
|
||||
def read_premises(root) -> str | Stop:
|
||||
try:
|
||||
found = sections(pathlib.Path(root, "README.md").read_text(encoding="utf-8"))
|
||||
except OSError as failure:
|
||||
@@ -22,7 +22,7 @@ def read_premises(root):
|
||||
return f"## Goals\n{found['Goals'][0]}\n\n## Audience\n{found['Audience'][0]}"
|
||||
|
||||
|
||||
def sections(text):
|
||||
def sections(text) -> dict[str, list[str]]:
|
||||
blocks, fenced = [], False
|
||||
for line in text.splitlines():
|
||||
fenced ^= line.startswith("```")
|
||||
|
||||
Reference in New Issue
Block a user