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