forge: doc_command_check report() tally loop -> Counter (DRY, behavior-preserving)

This commit is contained in:
forge committed 2026-10-20 20:53:27 +00:00
1 parent 223d9410ad
commit 86950bc00a
3 files changed
+290 -3

No files matched your search

+6 -3
View File
@@ -69,6 +69,7 @@ import re
import subprocess
import sys
import tempfile
from collections import Counter
# A documented command: `python3 <path>.py <args...>`. The path may be written
# as `tools/x.py` from the repo root or as `x.py` from inside `tools/`, which
@@ -228,9 +229,11 @@ def report(rep, out=sys.stdout):
miss = (" missing=%s" % (r["missing"],)) if r["missing"] else ""
print("%-18s %-30s -> %-26s %s%s"
% (r["verdict"], r["doc"], r["target"], r["detail"], miss), file=out)
counts = {}
for r in rep["rows"]:
counts[r["verdict"]] = counts.get(r["verdict"], 0) + 1
# `collections.Counter` replaces the hand-rolled tally loop: every entry's
# verdict is counted exactly as `counts[k] = counts.get(k, 0) + 1` did, and
# `sorted(counts)` still orders the keys, so the rendered summary is
# byte-identical -- this is a deletion of a duplicate loop, not a rewrite.
counts = Counter(r["verdict"] for r in rep["rows"])
print("doc commands at %s: %d command(s) over %d oracle(s) -- %s"
% (rep["rev"], len(rep["rows"]), rep["oracles"],
", ".join("%s %d" % (k, counts[k]) for k in sorted(counts)) or "none"))