go-python / go-python/gpython

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

未關閉
#257 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Go
星號
1k
分支
105
PR 合併指標
30 天內沒有已合併 PR

描述

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.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

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.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
go, python
領域
compilers
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
65/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。