Skip to content

[Bug]: Python mod.Box[T] annotation gets a false generic_arg edge that replaces the parameter_type one ('is' on tree-sitter nodes) #5110

Open

Description

@rohit-jsfreaky

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

A dotted generic annotation like def f(x: mod.MyBox[Foo]) gets a false references edge to MyBox with context: generic_arg. graph.json keeps one edge per node pair, so this false edge replaces the correct parameter_type / return_type edge.

The cause is in _python_collect_type_refs (graphify/extractors/engine.py), subscript branch:

for c in node.children:
    if c is value or not c.is_named:

py-tree-sitter returns a new Node object on every access, so c is value is never true (== works). The subscript's value is walked twice: once as the type, then again as one of its own generic arguments.

A plain MyBox[Foo] parses as generic_type and is not affected; only the dotted form is.

Steps to reproduce

# repro.py
import tree_sitter_python as tsp
from tree_sitter import Language, Parser
from graphify.extractors.engine import _python_collect_type_refs
src = b"def f(x: mod.MyBox[Foo]): ...\n"
tree = Parser(Language(tsp.language())).parse(src)
ann = tree.root_node.children[0].child_by_field_name("parameters").named_children[0].child_by_field_name("type")
out = []
_python_collect_type_refs(ann.named_children[0], src, False, out)
print(out)

Error output or graph output

got:      [('MyBox', 'type'), ('MyBox', 'generic_arg'), ('Foo', 'generic_arg')]
expected: [('MyBox', 'type'), ('Foo', 'generic_arg')]

Edges with the wrong context in real graphs: click 39, flask 21, requests 6 (django has almost no annotations, so 0).

Graphify version

0.9.105 (v8 at 5eedffa)

Operating System

Windows (also seen on Linux)

Python Version

3.12

Installation Method

uv tool install (recommended)

Activity

  1. github-actions commented on Nov 9, 2026

    @github-actions

    Thanks for opening this issue, @rohit-jsfreaky. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions