go-python / go-python/gpython

Multiple class definitions in the same file raise error "invalid syntax"

Aperta
#257 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
1k
Fork
105
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hey, there. It seems like it's not possible to define multiple classes in a single Python file with `py.RunSrc()`, unless I'm misunderstanding something...? It works with `py.RunFile()`, though.

Go:
```go

context := py.NewContext(py.DefaultContextOpts())

data, _ := fs.ReadFile(g.FS, "math_stuff.py")

_, err := py.RunSrc(context, string(data), "run", nil)

log.Println(err)

```

`math_stuff.py`
```python
class A:
pass

class B:
pass
```

Gives me the error:

```
2026/07/02 15:06:16
File "run", line 5, offset 5
class B:

SyntaxError: 'invalid syntax'
```

I'm testing with the latest commit.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start by reproducing the issue with py.RunSrc and the two-class math_stuff.py example, then compare its handling with py.RunFile. Trace the parser or source-loading path reached by py.RunSrc and add a regression test for multiple class definitions; done means the example runs without the invalid syntax error.

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

Valutazione

Stack tecnologico
go, python
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
65/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.