Answer architecture round 1: 1 🔴, 1 🟡; build the report text in a pure function, and parse anchor rows and IDs with todo_table's parsers

This commit is contained in:
2026-10-16 19:41:53 +02:00
parent c0dce6c887
commit 0f3434f2c5
4 changed files with 52 additions and 44 deletions
+9 -2
View File
@@ -230,10 +230,17 @@ def parse_scores(id_: str, named: dict[str, str], names: tuple[str, ...]) -> dic
return scores
def parse_blockers(id_: str, cell: str) -> tuple[int, ...] | Failure:
def parse_ids(cell: str) -> tuple[int, ...] | None:
"""The item IDs a cell lists, such as `12, 14`, none where it is empty; None where it holds anything else."""
if not re.fullmatch(r"([0-9]+(, [0-9]+)*)?", cell):
return None
return tuple(int(id_) for id_ in cell.split(", ") if id_)
def parse_blockers(id_: str, cell: str) -> tuple[int, ...] | Failure:
blocked_by = parse_ids(cell)
if blocked_by is None:
return Failure(f"item {id_}'s {BLOCKED_BY} {cell!r} is not empty or IDs separated by \", \"")
blocked_by = tuple(int(blocker) for blocker in cell.split(", ") if blocker)
if int(id_) in blocked_by:
return Failure(f"item {id_} is blocked by itself; drop {id_} from its {BLOCKED_BY}")
return blocked_by