Skip to content

fix(parsers): recover Python annotated parameters (40% loss) and Go grouped imports - #1561

Merged
Shashankss1205 merged 1 commit into
mainfrom
fix/parser-python-typed-params
Aug 2, 2026
Merged

Shashankss1205 merged 1 commit into
mainfrom
fix/parser-python-typed-params

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Fixes #1520 and #1521 — two parser defects that silently dropped large fractions of the graph. Both were found by an audit and are reproduced below.

Full suite: 1065 passed, 7 skipped, no failures.

Python — annotated parameters without a default (#1520)

typed_parameter has no name field in tree-sitter-python; it exposes only type. Its children are (<identifier|splat>, ':', type):

typed_parameter -> children: [('identifier', 'x'), (':', ':'), ('type', 'int')]

So child_by_field_name('name') returned None and the parameter was discarded. x: int = 5 survived only because it is a different node type — typed_default_parameter, which does have the field — which is exactly why this went unnoticed for so long.

The fix reads the first child instead, and covers the splat forms (*args: int, **kw: str) that also appear in that position.

Measured against the stdlib ast module over src/codegraphcontext/:

parameters
declared (ast) 3271
extracted before 1952 (1319 lost, 40.3%)
extracted after 3271 (0 lost)

Since this repo is heavily annotated, self-indexing was losing over 40% of Parameter nodes and their HAS_PARAMETER edges.

Go — grouped import (...) blocks (#1521)

The imports query required import_spec to be a direct child of import_declaration. That shape only occurs for a single-line import "fmt"; a grouped block nests them one level deeper:

import_declaration
└── import_spec_list          <- not matched
    ├── import_spec  "context"
    └── import_spec  "fmt"

gofmt rewrites any file with more than one import into a grouped block, so essentially every real Go file lost every import. With no Module nodes and no IMPORTS edges, cross-file call resolution for Go had nothing to work from.

Added the nested alternatives for both the plain and aliased forms. Verified:

grouped:        [('context', None), ('fmt', None), ('sql', 'sql')]
single:         [('fmt', None)]
aliased single: [('fmt', 'f')]

The repo's own sample_project_go/main.go fixture went from 0 imports to 2.

Goldens

sample_project and sample_project_go regenerated. Both diffs are purely additive — verified by counting node labels before and after:

sample_project:     Parameter  139 -> 143   (+4)
sample_project_go:  Module       2 ->  16   (+14)

No nodes lost in either. I deliberately did not touch the goldens for other languages.

Note for reviewers

Fixing parsers changes what the graph contains, so node and edge counts will move. That is the point of the change, but it will shift the numbers in #1393 and is worth keeping in mind for the Database Parity Check. The remaining parser bugs (#1522 PHP, #1523 Ruby, #1524 C/C++, #1526 JS/TS) will each do the same, so they are probably best merged deliberately rather than all at once.

🤖 Generated with Claude Code

Two parser defects that silently dropped large fractions of the graph.

Python — annotated parameters without a default (#1520)

`typed_parameter` has no `name` field in tree-sitter-python, only `type`.
Looking one up returned None, so every `x: int` parameter was discarded.
`x: int = 5` survived only because it is a different node type
(`typed_default_parameter`, which does have the field), which is why the
gap went unnoticed. Read the first child instead, covering the `*args: T`
and `**kw: T` splat forms too.

Measured against the stdlib `ast` module over `src/codegraphcontext/`:

    before:  1952 / 3271 parameters extracted  (1319 lost, 40.3%)
    after:   3271 / 3271                       (0 lost)

Go — grouped `import (...)` blocks (#1521)

The imports query required `import_spec` to be a direct child of
`import_declaration`. That shape only occurs for a single-line
`import "fmt"`; a grouped block nests the specs inside an
`import_spec_list`. Since gofmt groups any file with more than one
import, essentially every real Go file lost every import — and with no
Module nodes there is nothing for cross-file resolution to work from.
Added the nested alternatives for both the plain and aliased forms.

Goldens for `sample_project` (+4 Parameter) and `sample_project_go`
(+14 Module) regenerated; both diffs are purely additive, no nodes lost.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
code-graph-context-pack Ready Ready Preview Aug 2, 2026 5:24pm

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Code Graph Analysis

fix(parsers): recover Python annotated parameters (40% loss) and Go grouped imports (#1561)

📊 Interactive Visualization

View the blast radius graph: PR Reviewer Dashboard

📦 Artifacts

The graph JSON has been uploaded as a build artifact: pr-code-graph-1561


Generated by CodeGraphContext using FalkorDB Lite

@Shashankss1205
Shashankss1205 merged commit 458fd50 into main Aug 2, 2026
19 checks passed
@Shashankss1205
Shashankss1205 deleted the fix/parser-python-typed-params branch August 2, 2026 17:40
@github-project-automation github-project-automation Bot moved this from Backlog tasks to Done in CGC Progress Board Aug 2, 2026
Shashankss1205 added a commit that referenced this pull request Aug 2, 2026
Bug-fix release. Since 0.5.4 on PyPI:

- fix(indexer): record non-code files on the SCIP path so `cgc index`
  stops reporting a partial index forever (#1565, #1566)
- fix(parsers): capture PHP imports rather than trait uses (#1522, #1563)
- fix(parsers): recover Python annotated parameters — 40.3% of parameters
  were being dropped — and Go grouped imports (#1520, #1521, #1561)
- fix(graph): always sanitize bundle filenames (#1517, #1541)
- fix(cli/mcp): read import aliases from the IMPORTS relationship (#1515, #1540)
- fix(cli/mcp): fall back to JSON when GCF encoding fails (#1518, #1539)

Co-authored-by: Claude Fable 5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 9910e959 Deployed Aug 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(indexer): Python annotated parameters without a default (x: str) are silently dropped — 41.8% of parameters lost

1 participant