Answer architecture round 1: 0 🔴, 2 🟡 (0 misread); read a round title's counts once, into one Counts value

This commit is contained in:
2026-10-23 11:30:17 +02:00
parent 4d18b8e125
commit 80cc36e904
4 changed files with 50 additions and 47 deletions
+26 -19
View File
@@ -1,4 +1,5 @@
"""The titles of larv-review's round commits, `Answer <pass> round <n>: <k> 🔴, <m> 🟡 (<j> misread); <summary>`: each pass's round count, and the findings the rounds reported. <j> counts the 🔴 and 🟡 findings a reviewer marked `[misread]`, because the implementer misread code that had already shipped."""
import dataclasses
import re
from review_passes import PASSES
@@ -10,6 +11,14 @@ ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE)
FINDINGS = re.compile(r" ([0-9]+) 🔴, ([0-9]+) 🟡(?: \(([0-9]+) misread\))?(?:;|$)")
@dataclasses.dataclass(frozen=True)
class Counts:
"""A round title's findings: its 🔴 and 🟡 counts, and how many of them were misread, None for a title from before that count."""
red: int
yellow: int
misread: int | None
def round_counts(titles: list[str]) -> dict[str, int]:
"""Each pass's round count among the branch's `Answer <pass> round <n>:` commit titles: the highest <n>, or the number of such commits where that is more, so a repeated number still counts. A pass with none has 0, and a title naming no known pass adds its name. Case is ignored."""
highest: dict[str, int] = dict.fromkeys(PASSES, 0)
@@ -24,8 +33,7 @@ def round_counts(titles: list[str]) -> dict[str, int]:
def lacks_counts(title: str) -> bool:
"""Whether title is a round title without all three counts after its colon."""
named = ROUND.match(title)
return named is not None and ((found := FINDINGS.match(title, named.end())) is None or found.group(3) is None)
return ROUND.match(title) is not None and ((counts := title_counts(title)) is None or counts.misread is None)
def past_cap(title: str) -> bool:
@@ -34,25 +42,24 @@ def past_cap(title: str) -> bool:
return named is not None and int(named.group(2)) > CAP
def round_findings(titles: list[str]) -> tuple[int, int] | None:
"""The 🔴 and 🟡 counts summed over the round titles among titles; None where a round title lacks them, or no title is a round."""
counts = []
for title in titles:
if named := ROUND.match(title):
found = FINDINGS.match(title, named.end())
if not found:
return None
counts.append((int(found.group(1)), int(found.group(2))))
return (sum(red for red, _ in counts), sum(yellow for _, yellow in counts)) if counts else None
def title_counts(title: str) -> Counts | None:
"""The counts after a round title's colon; None where title is no round title, or lacks the 🔴 and 🟡 counts."""
named = ROUND.match(title)
found = FINDINGS.match(title, named.end()) if named else None
if not found:
return None
return Counts(int(found.group(1)), int(found.group(2)), None if found.group(3) is None else int(found.group(3)))
def round_misreads(titles: list[str]) -> int | None:
"""The misread counts summed over the round titles among titles; None where a round title lacks one, or no title is a round."""
def round_findings(titles: list[str]) -> Counts | None:
"""The counts summed over the round titles among titles; None where a round title lacks the 🔴 and 🟡 counts, or no title is a round. Its misread is None where a round title lacks that count."""
counts = []
for title in titles:
if named := ROUND.match(title):
found = FINDINGS.match(title, named.end())
if not found or found.group(3) is None:
if ROUND.match(title):
if (found := title_counts(title)) is None:
return None
counts.append(int(found.group(3)))
return sum(counts) if counts else None
counts.append(found)
if not counts:
return None
misreads = [found.misread for found in counts if found.misread is not None]
return Counts(sum(found.red for found in counts), sum(found.yellow for found in counts), sum(misreads) if len(misreads) == len(counts) else None)