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:
+9
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user