Skip to content

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

Description

@SolarLune

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:

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions