Skip to content

The agent that grows with you

fix(code-health): measure every Python unit's real end line

Tekniumfccb46ac4828
diff --git a/scripts/code_health/measure.py b/scripts/code_health/measure.py
index 3ff7692d68e..fac5a222b23 100644
--- a/scripts/code_health/measure.py
+++ b/scripts/code_health/measure.py
@@ -193,4 +193,5 @@ class Measurer:
line=unit["line"],
metrics={"CC": unit["cc"], "FUNC_LINES": unit["lines"], "NESTING": unit["nesting"]},
body_hash=unit["hash"],
+ end_line=unit.get("end"),
)
diff --git a/scripts/code_health/py_structure.py b/scripts/code_health/py_structure.py
index 448456031aa..73c72365f36 100644
--- a/scripts/code_health/py_structure.py
+++ b/scripts/code_health/py_structure.py
@@ -167,7 +167,8 @@ class _UnitCollector(ast.NodeVisitor):
# A class has no size metrics of its own, but it is a unit so that a renamed or moved
# class keeps the violations in its body (decorators, attributes) one-to-one.
self.units[qual] = Unit(qualname=qual, line=node.lineno, metrics={},
- body_hash=body_hash(node), parent=self.funcs[-1] if self.funcs else None)
+ body_hash=body_hash(node), parent=self.funcs[-1] if self.funcs else None,
+ end_line=node.end_lineno)
self.spans.append(Span(_first_line(node), node.end_lineno or node.lineno, qual))
self.stack.append(qual.rsplit(".", 1)[-1])
self.generic_visit(node)
@@ -184,6 +185,7 @@ class _UnitCollector(ast.NodeVisitor):
metrics={"FUNC_LINES": end - first + 1, "NESTING": nesting_depth(node.body)},
body_hash=body_hash(node),
parent=self.funcs[-1] if self.funcs else None,
+ end_line=end,
)
self.spans.append(Span(first, end, qual))
self.stack.append(qual.rsplit(".", 1)[-1])