Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug]: Python files can disappear from the graph when a class is used before it's defined

Chiusa
#4,334 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #4343 di @Mpasha17 — chiusa senza merge

Valutazione

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

Direzione di ricerca

Start by running graphify update . on the two-file reproduction in the issue and inspect graphify-out/graph.json to trace how the class reference before its definition affects file and class nodes. Find the Python parsing and graph construction entry points that handle those references; the issue does not name specific source files or tests. Done means widget.py remains in the graph, references resolve to its Widget class, and the missing call from Helper.make appears.

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

Descrizione

What's happening

In some Python projects, whole files go missing from the graph, and the classes inside them get tangled up. There's no error, so it's easy to miss.

I noticed it on rich: when I ran graphify update rich/rich, two of its main files, markdown.py and syntax.py, weren't in the graph at all.

When it happens:

  • the file itself disappears from the graph
  • the class with the same name as the file ends up "containing" itself and every other class in the file
  • other files that import it look like they import the class instead of the file
  • some calls made from inside that file are quietly left out

When it happens

All three of these at once:

  1. The file is directly in the folder you point graphify at, not in a subfolder
  2. It has a class with the same name as the file, like Widget in widget.py
  3. Something earlier in that file mentions the class before it's defined, like a type hint w: Widget

Naming a file after its main class is pretty common, like console.py with Console, so this shows up in real projects.

How to see it for yourself

Make a folder with these two files and run graphify update .:

widget.py

from __future__ import annotations

class Helper:
    def make(self, w: Widget) -> None:
        w.draw()

class Widget:
    def draw(self):
        return 1

app.py

from widget import Widget

def use(w: Widget):
    w.draw()

Then look at graphify-out/graph.json:

  • there's no widget.py node
  • Widget "contains" itself and Helper
  • app.py imports Widget the class instead of widget.py the file
  • the call from Helper.make to Widget.draw is missing, while the same call from app.py is there

What should happen

widget.py should be in the graph like any other file, and the Widget it mentions should just point to the class defined lower down in the same file.

How much it matters

I checked graphify's call links against Jedi on rich. On 0.9.85, with this fixed, graphify finds 54 more correct calls, going from 64.6% to 68.6%, with no wrong links added and none lost. Both missing files come back too.


Version: graphify 0.9.85 · macOS 26.4 · Python 3.14

Lingua principale
Python
Stelle
124k
Fork
11.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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.