Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(health): name a perf step's function and mark async extractions in Fix first steps (#3273)
Raghav Chamadiya5b4e9cf42c88
diff --git a/packages/core/src/repowise/core/analysis/health/fix_first/build.py b/packages/core/src/repowise/core/analysis/health/fix_first/build.pyindex cd983528b..cd9dd6dfe 100644--- a/packages/core/src/repowise/core/analysis/health/fix_first/build.py+++ b/packages/core/src/repowise/core/analysis/health/fix_first/build.py@@ -51,6 +51,7 @@ from __future__ import annotationsimport functoolsimport math+import refrom collections import Counter, defaultdictfrom collections.abc import Callable, Iterable, Mappingfrom dataclasses import dataclass@@ -419,6 +420,7 @@ class _Files:body.get("suggested_name"),list(body.get("params") or []),list(body.get("returns") or []),+ is_async=bool(body.get("needs_async", False)),)return FixStep(1, f"Extract lines {start}-{end} of {tail} into {into}", path, start)shape = self.shape(path, function)@@ -611,6 +613,7 @@ def _refactor_step(order: int, step: Mapping[str, Any], plan: Any) -> FixStep:body.get("suggested_name"),list(body.get("params") or []),list(body.get("returns") or []),+ is_async=bool(body.get("needs_async", False)),)where = f"lines {start}-{end} of {sym}" if start and end else f"part of {sym}"line_text = f"Extract {where} into {into}"@@ -961,7 +964,10 @@ def _perf_step_text(step: Mapping[str, Any], path: str) -> str:says the name is not followed by it again."""action = step.get("action") or ""name = text.scope_name(step.get("symbol"), path)- if not name or name.rsplit(".", 1)[-1] in action:+ # A whole word that is not an attribute: ``get`` is not named by a quoted+ # ``session.get`` call, nor by ``getattr``.+ short = name.rsplit(".", 1)[-1] if name else ""+ if not name or re.search(rf"(?<![\w.]){re.escape(short)}(?!\w)", action):return actionreturn f"{action} ({name})"diff --git a/packages/core/src/repowise/core/analysis/health/fix_first/text.py b/packages/core/src/repowise/core/analysis/health/fix_first/text.pyindex 02b997528..a1e25235d 100644--- a/packages/core/src/repowise/core/analysis/health/fix_first/text.py+++ b/packages/core/src/repowise/core/analysis/health/fix_first/text.py@@ -335,11 +335,18 @@ def history_fact(marker: str, details: dict, function: str | None = None) -> strreturn None-def signature(name: str | None, params: list[str], returns: list[str]) -> str:- """``compute_x(a, b) -> c``; a long parameter list is cut with its count."""+def signature(+ name: str | None, params: list[str], returns: list[str], *, is_async: bool = False+) -> str:+ """``compute_x(a, b) -> c``; a long parameter list is cut with its count.+ A span that awaits becomes ``async compute_x(...)``, awaited where it was."""shown = ", ".join(params[:4]) + (f", +{len(params) - 4} more" if len(params) > 4 else "")- out = f"{name}({shown})" if name else "a helper" + (f" taking ({shown})" if params else "")- return out + (f" -> {', '.join(returns[:3])}" if returns else "")+ helper = "an async helper" if is_async else "a helper"+ out = f"{name}({shown})" if name else helper + (f" taking ({shown})" if params else "")+ out += f" -> {', '.join(returns[:3])}" if returns else ""+ if not is_async:+ return out+ return f"{'async ' if name else ''}{out}, awaited at the call site"def first_sentence(text: str) -> str:diff --git a/tests/unit/health/test_fix_first_precision.py b/tests/unit/health/test_fix_first_precision.pyindex 17269ffb6..07910d084 100644--- a/tests/unit/health/test_fix_first_precision.py+++ b/tests/unit/health/test_fix_first_precision.py@@ -555,3 +555,24 @@ def test_a_rust_panic_path_is_no_fix_first_candidate() -> None:assert queue.items == () and queue.totals.excluded["low_value_kind"] == 2swallowed = {**rows[0], "file_path": "src/a.py", "details": {"kind": "swallowed_catch"}}assert [i.target.file_path for i in _queue([swallowed]).items] == ["src/a.py"]+++def test_a_perf_step_names_its_function_unless_the_action_already_does() -> None:+ from repowise.core.analysis.health.fix_first.build import _perf_step_text++ quoted = {"action": "Batch the per-row session.get calls", "symbol": "src/db.py::Store.get"}+ assert _perf_step_text(quoted, "src/db.py") == f"{quoted['action']} (Store.get)"+ named = {"action": "Pass every key to get at once", "symbol": "src/db.py::Store.get"}+ assert _perf_step_text(named, "src/db.py") == named["action"]+++def test_a_span_that_awaits_is_extracted_into_an_awaited_async_helper() -> None:+ from repowise.core.analysis.health.fix_first import text++ assert text.signature("load_rows", ["db"], ["rows"]) == "load_rows(db) -> rows"+ assert text.signature("load_rows", ["db"], ["rows"], is_async=True) == (+ "async load_rows(db) -> rows, awaited at the call site"+ )+ assert text.signature(None, ["db"], [], is_async=True) == (+ "an async helper taking (db), awaited at the call site"+ )