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

Open Beginner friendly
#5,110 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@rohit-jsfreaky is already working on this.

Since Nov 9, 2026.

  • #5113 by @rohit-jsfreaky — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend, devtools

Research direction

Start in graphify/extractors/engine.py at _python_collect_type_refs, specifically the subscript branch described in the issue. Reproduce the case with mod.MyBox[Foo] and compare the collected references with the expected output. Done means the extra MyBox generic_arg reference is gone while the type and Foo generic_arg references remain.

Written by the indexing model from the issue text.

Description

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 5eedffa8)

Operating System

Windows (also seen on Linux)

Python Version

3.12

Installation Method

uv tool install (recommended)

Dominant language
Python
Stars
124k
Forks
11.9k
Avg merge
2h 35m
Merged PRs (30d)
6

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Graphify-Labs/graphify

All issues in Graphify-Labs/graphify

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.