go-python / go-python/gpython

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

Ouverte
#257 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Go
Étoiles
1k
Forks
105
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
go, python
Domaine
compilers
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
65/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.