Title: py: fix RunSrc to allow multiple top-level statements (#257) by ncw · Pull Request #258 · go-python/gpython · GitHub
Open Graph Title: py: fix RunSrc to allow multiple top-level statements (#257) by ncw · Pull Request #258 · go-python/gpython
X Title: py: fix RunSrc to allow multiple top-level statements (#257) by ncw · Pull Request #258 · go-python/gpython
Description: Problem py.RunSrc fails with SyntaxError: 'invalid syntax' when the source contains more than one top-level statement — for example, two class definitions: class A: pass class B: pass The equivalent py.RunFile path works fine. Reported in #257. Root cause RunSrc compiled the source in SingleMode: code, err := Compile(pySrc+"\n", pySrcDesc, SingleMode, 0, true) SingleMode maps to Python's single/interactive grammar, which accepts only a single top-level statement. RunFile goes through ResolveAndCompile, which uses ExecMode (the file/module grammar that accepts a whole module of statements) — hence the discrepancy. This has been present since RunSrc was introduced in 727b7c4. Fix Compile in ExecMode instead, matching RunFile and the semantics of Python's exec() for a source buffer. Test Adds TestRunSrcMultipleStatements in pytest (which imports both py and stdlib, avoiding the import cycle in the py package). Verified it fails against the old SingleMode code and passes with the fix. Full suite green. Fixes #257
Open Graph Description: Problem py.RunSrc fails with SyntaxError: 'invalid syntax' when the source contains more than one top-level statement — for example, two class definitions: class A: pass class B: ...
X Description: Problem py.RunSrc fails with SyntaxError: 'invalid syntax' when the source contains more than one top-level statement — for example, two class definitions: class A: pass class...
Opengraph URL: https://github.com/go-python/gpython/pull/258
X: @github
Domain: Github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:af2a18c8-43e5-90c9-a5a0-72258902ccc5 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CA78:37BBED:975521:D4EF8E:6A624B9B |
| html-safe-nonce | 5514db86aad686922f662c2cd34c1f01cd776947adaa01942cf2f53a6594ca8a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTc4OjM3QkJFRDo5NzU1MjE6RDRFRjhFOjZBNjI0QjlCIiwidmlzaXRvcl9pZCI6IjgwMjc3MDM0NjMyNzAwNDI1MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a06f8ea3a5d0a2d2b7a5dbe290eb38a8e58aa916e5e29ec54d874a4b99df7e8e |
| hovercard-subject-tag | pull_request:3986656823 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/go-python/gpython/pull/258/files |
| twitter:image | https://avatars.githubusercontent.com/u/536803?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/536803?s=400&v=4 |
| og:image:alt | Problem py.RunSrc fails with SyntaxError: 'invalid syntax' when the source contains more than one top-level statement — for example, two class definitions: class A: pass class B: ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 77f5af7d0fa3843b1779a53f60ec016b3f962e46051fb05c2e9b608a8138eefb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/go-python/gpython git https://github.com/go-python/gpython.git |
| octolytics-dimension-user_id | 7604679 |
| octolytics-dimension-user_login | go-python |
| octolytics-dimension-repository_id | 143203535 |
| octolytics-dimension-repository_nwo | go-python/gpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143203535 |
| octolytics-dimension-repository_network_root_nwo | go-python/gpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d3ce7d369aae307e197872f810f80f3ed9051c78 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width