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

Aperta Adatta ai principianti
#5,110 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@rohit-jsfreaky ci sta già lavorando.

Dal 9/11/2026.

  • #5113 di @rohit-jsfreaky — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, devtools

Direzione di ricerca

Inizia in graphify/extractors/engine.py, in _python_collect_type_refs, nello specifico nel ramo subscript descritto nell’issue. Riproduci il caso con mod.MyBox[Foo] e confronta i riferimenti raccolti con l’output previsto. Il lavoro è completato quando il riferimento generic_arg aggiuntivo di MyBox è scomparso, mentre restano i riferimenti generic_arg di type e Foo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)

Lingua principale
Python
Stelle
124k
Fork
11.9k
Merge medio
2h 35m
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Graphify-Labs/graphify

Tutte le issue di Graphify-Labs/graphify

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.