Skip to content

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

Closed

Description

@Shashankss1205

tools/languages/python.py:304-307

Parameter extraction looks up a name field on every parameter node:

child.child_by_field_name('name')

In tree-sitter-python, typed_default_parameter (x: int = 5) has a name field, but typed_parameter (x: int) does not — it exposes only type. So the lookup returns None and the parameter is silently discarded.

Reproduction

$ .venv/bin/python -c "
from codegraphcontext.tools.tree_sitter_parser import TreeSitterParser
from codegraphcontext.tools.languages.python import PythonTreeSitterParser
import tempfile, pathlib
p = pathlib.Path(tempfile.mkdtemp())/'t.py'
p.write_text('def m(self, x: str, y, z: int = 5): pass\n')
print(PythonTreeSitterParser(TreeSitterParser('python')).parse(str(p))['functions'][0]['args'])
"
['self', 'y', 'z']

x: str is gone. z: int = 5 survives only because it is a different node type.

Blast radius

Measured against the stdlib ast module over CGC's own src/:

real parameters (ast):        3154
extracted by the parser:      1835
lost:                         1319   (41.8%)

Every annotated-but-undefaulted parameter — the dominant style in any typed Python codebase, and in this repo — never becomes a Parameter node and never gets a HAS_PARAMETER edge. Since CGC's own source is heavily annotated, self-indexing loses over 40% of parameters.

Suggested fix

Handle typed_parameter explicitly: its identifier is the first identifier child rather than a name field.


Environment
Commit c0e0bed (main)
Python 3.12.3, Linux

Reproduced with the snippet above; the 41.8% figure measured by diffing parser output against ast over src/.

Activity

  1. added
    bugSomething isn't working
    severity: highWrong graph content, data loss, or a broken workflow with no clear signal
    area: indexerParsing, discovery, resolution, persistence
    on Aug 1, 2026
  2. github-actions commented on Aug 1, 2026

    @github-actions
    Contributor

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

  3. moved this from Backlog tasks to In progress in CGC Progress Boardon Aug 2, 2026
  4. moved this from In progress to Done in CGC Progress Boardon Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: indexerParsing, discovery, resolution, persistencebugSomething isn't workingseverity: highWrong graph content, data loss, or a broken workflow with no clear signal

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions