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
+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.