Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(health): don't count comments in a parameter list as parameters (#1796)

Sloeb14630a2d965
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
index 0d28fc864..116c97114 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
@@ -240,7 +240,10 @@ def _count_parameters(fn_node: Node) -> int:
# A bare ``*`` (keyword-only marker) and a bare ``/`` (positional-only
# marker) parse as named ``keyword_separator`` / ``positional_separator``
# nodes but carry no arity, so they must be skipped alongside the
- # ``*``/``**`` splat tokens and the punctuation.
+ # ``*``/``**`` splat tokens and the punctuation. A ``comment`` node is
+ # also named but carries no arity — an explanatory comment block inside
+ # the parameter list (idiomatic for a validation pattern) must not
+ # count as a parameter (#1775).
if child.type in (
"(",
")",
@@ -252,6 +255,7 @@ def _count_parameters(fn_node: Node) -> int:
"**",
"keyword_separator",
"positional_separator",
+ "comment",
):
continue
if child.type == "declArg":
diff --git a/tests/unit/health/test_complexity_walker.py b/tests/unit/health/test_complexity_walker.py
index 7207e97ed..018488b24 100644
--- a/tests/unit/health/test_complexity_walker.py
+++ b/tests/unit/health/test_complexity_walker.py
@@ -95,6 +95,31 @@ def test_python_complex_method_ccn():
assert many.ccn >= 9, f"expected CCN ≥ 9, got {many.ccn}"
+def test_python_comment_in_parameter_list_not_counted():
+ """#1775: a comment inside a parameter list must not inflate param_count.
+
+ ``Annotated[T, Form(...)]`` metadata and an explanatory comment block are
+ idiomatic in FastAPI/Pydantic signatures. The comment node is named but
+ carries no arity; before the fix it was counted, so a 5-parameter handler
+ reported 6+ (and worse on longer signatures) and tripped a spurious
+ high-arity finding.
+ """
+ src = """async def trigger_scan(
+ request: Request,
+ session: Annotated[AsyncSession, Depends(get_session)],
+ # comment with, several, commas explaining the pattern
+ agent_id: Annotated[str, Form(pattern=r\"^[a-z0-9]+(-[a-z0-9]+)*$\", max_length=128)],
+ scan_root: Annotated[str, Form()],
+ subpath: Annotated[str, Form()] = \"\",
+) -> HTMLResponse:
+ pass
+"""
+ fcx = walk_file("/tmp/trigger.py", "python", src.encode())
+ fn = _find(fcx.functions, "trigger_scan")
+ assert fn is not None
+ assert fn.param_count == 5, f"expected 5 params, got {fn.param_count}"
+
+
def test_typescript_nested_depth():
results = _walk("typescript/nested.ts", "typescript")
deep = _find(results, "deeplyNested")