Skip to content

Fix argument counting to ignore commas within nested brackets/types - #1036

Merged
squid-protocol merged 1 commit into
mainfrom
fix/1019-nested-bracket-arg-counting
Aug 4, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/1019-nested-bracket-arg-counting

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

  • Closes Fix argument counting to ignore commas within nested brackets/types #1019. StructuralExtractor._calculate_block_metrics counted arguments by running .count(",") over the whole captured function signature, so any nested comma — generic type hints (Map<A, B>, Dict[str, int]), default dict/list literals, or nested callback signatures — inflated the count as if each were a separate top-level argument.
  • Added StructuralExtractor._count_top_level_args (gitgalaxy/core/detector.py): a depth- and string-aware sweep that isolates the argument list's own bracket body (captured signatures include the wrapping (...), e.g. "def foo(x, y)") and only counts commas at that top level, tracking (), [], {}, <> nesting and skipping commas inside string literals.

Why the golden masters changed

Both tests/golden_master_audit.json and tests/golden_master_zero_dep_audit.json are re-blessed via tests/tools/update_golden_master.py, per the Differential Scan protocol in CLAUDE.md. Real corpus code with nested-bracket signatures now scores a correspondingly lower argument count, cascading into structural magnitude / 3D coordinates for those files (e.g. FastAPI's HTTPException.__init__, whose params are wrapped in heavily-nested Annotated[..., Doc("""...""")] hints, previously way overcounted). crucible_check.py passes clean against the new baselines in both full-precision and zero-dependency mode.

Test plan

  • python -m pytest tests/core_engine/ — 2904 passed, 1 xfailed
  • python -m pytest tests/core_engine/test_language_standards_strict.py -k perl and tests/extraction/languages/test_perl.py — unaffected
  • python tests/tools/crucible_check.py — PASS (full_precision + zero_dependency)
  • python tests/tools/audit_check.py — ruff/mypy/dead-key all clean
  • Manual synthetic cases: def foo(data: Dict[str, int]) → 1 arg, def foo(data: dict = {"x": 1, "y": 2}, z=5) → 2 args, foo(Map<String, Integer> data, int y) → 2 args, TS nested-callback param → 2 args

🤖 Generated with Claude Code

)

The args_count heuristic ran .count(",") over the whole captured
signature, so nested commas -- generic type hints (Map<A, B>,
Dict[str, int]), default dict/list literals, and nested callback
signatures -- each inflated the count as if they were separate top-
level arguments. StructuralExtractor._count_top_level_args replaces
this with a depth- and string-aware sweep that only counts commas at
the argument list's own nesting level, tracking (), [], {}, <> and
skipping commas inside string literals.

This changes structural magnitude / 3D coordinates across the golden
master corpus wherever real signatures carry nested brackets (e.g.
FastAPI's heavily Annotated[...] parameters), so both
tests/golden_master_audit.json and golden_master_zero_dep_audit.json
are re-blessed via tests/tools/update_golden_master.py per the
Differential Scan protocol. crucible_check.py passes clean against
the new baselines in both full-precision and zero-dependency mode.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit d5a604d into main Aug 4, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the fix/1019-nested-bracket-arg-counting branch August 4, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix argument counting to ignore commas within nested brackets/types

1 participant