Answer architecture round 4: count only what a target assigns, end each log entry with a newline, and give the larv-review hint only for the default history

This commit is contained in:
2026-10-08 23:09:10 +02:00
parent e67c882a08
commit 737d58ad9f
4 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ class RunScores:
def co_changed(log: str) -> dict[str, int]:
"""For each file, how many other files changed in a commit with it, commits of more than LARGEST_CHANGESET files left out; log is `git log --format=format:@@ --name-only`."""
"""For each file, how many other files changed in a commit with it, commits of more than LARGEST_CHANGESET files left out; log is `git log --format=tformat:@@ --name-only`."""
partners: dict[str, set[str]] = collections.defaultdict(set)
for commit in log.split("@@\n"):
files = set(filter(None, commit.split("\n")))
+2 -2
View File
@@ -68,7 +68,7 @@ def read_history(given: pathlib.Path | None) -> tuple[str, pathlib.Path, str] |
if isinstance(found, Failure):
return found
history = given or pathlib.Path(found.strip(), "docs", "comprehension-history.md")
if not history.exists():
if not given and not history.exists():
return Failure(f"no comprehension history at {history}; larv-review writes one at a project's first paired ruling or scoring run")
try:
return found.strip(), history, history.read_text(encoding="utf-8")
@@ -117,7 +117,7 @@ def run_scores(run: ScoringRun, top: str) -> tuple[RunScores | None, list[str]]
unparsed.append(found.reason)
else:
units += found
log = git(["-c", "core.quotePath=false", "log", "--no-merges", "--format=format:@@", "--name-only", run.commit], top)
log = git(["-c", "core.quotePath=false", "log", "--no-merges", "--format=tformat:@@", "--name-only", run.commit], top)
if isinstance(log, Failure):
return log
places, dropped = resolved(run.places, tracked)
+10 -1
View File
@@ -65,7 +65,16 @@ def written(node: ast.AST) -> list[ast.expr]:
targets = [node.optional_vars]
else:
return []
return [leaf for target in targets for leaf in ast.walk(target) if isinstance(leaf, ast.Attribute)]
return [leaf for target in targets for leaf in assigned(target)]
def assigned(target: ast.expr) -> list[ast.expr]:
"""What a target writes: each part of an unpacking, and for `x[i] = …` the x."""
if isinstance(target, ast.Tuple | ast.List):
return [leaf for element in target.elts for leaf in assigned(element)]
if isinstance(target, ast.Starred | ast.Subscript):
return assigned(target.value)
return [target]
# SonarSource's "Cognitive Complexity" white paper (G. Ann Campbell, 2017), read for Python: a comprehension counts as a loop and each of its `if` clauses as a condition.