René's URL Explorer Experiment


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

direct link

Domain: Github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:af2a18c8-43e5-90c9-a5a0-72258902ccc5
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idCA78:37BBED:975521:D4EF8E:6A624B9B
html-safe-nonce5514db86aad686922f662c2cd34c1f01cd776947adaa01942cf2f53a6594ca8a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTc4OjM3QkJFRDo5NzU1MjE6RDRFRjhFOjZBNjI0QjlCIiwidmlzaXRvcl9pZCI6IjgwMjc3MDM0NjMyNzAwNDI1MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaca06f8ea3a5d0a2d2b7a5dbe290eb38a8e58aa916e5e29ec54d874a4b99df7e8e
hovercard-subject-tagpull_request:3986656823
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/go-python/gpython/pull/258/files
twitter:imagehttps://avatars.githubusercontent.com/u/536803?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/536803?s=400&v=4
og:image:altProblem 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_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None77f5af7d0fa3843b1779a53f60ec016b3f962e46051fb05c2e9b608a8138eefb
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/go-python/gpython git https://github.com/go-python/gpython.git
octolytics-dimension-user_id7604679
octolytics-dimension-user_logingo-python
octolytics-dimension-repository_id143203535
octolytics-dimension-repository_nwogo-python/gpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id143203535
octolytics-dimension-repository_network_root_nwogo-python/gpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
released3ce7d369aae307e197872f810f80f3ed9051c78
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://Github.com/go-python/gpython/pull/258/files#start-of-content
https://Github.com/
Sign in https://Github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgo-python%2Fgpython%2Fpull%2F258%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://Github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgo-python%2Fgpython%2Fpull%2F258%2Ffiles
Sign up https://Github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=go-python%2Fgpython
Reloadhttps://Github.com/go-python/gpython/pull/258/files
Reloadhttps://Github.com/go-python/gpython/pull/258/files
Reloadhttps://Github.com/go-python/gpython/pull/258/files
Please reload this pagehttps://Github.com/go-python/gpython/pull/258/files
go-python https://Github.com/go-python
gpythonhttps://Github.com/go-python/gpython
Notifications https://Github.com/login?return_to=%2Fgo-python%2Fgpython
Fork 105 https://Github.com/login?return_to=%2Fgo-python%2Fgpython
Star 1k https://Github.com/login?return_to=%2Fgo-python%2Fgpython
Code https://Github.com/go-python/gpython
Issues 49 https://Github.com/go-python/gpython/issues
Pull requests 5 https://Github.com/go-python/gpython/pulls
Actions https://Github.com/go-python/gpython/actions
Projects https://Github.com/go-python/gpython/projects
Wiki https://Github.com/go-python/gpython/wiki
Security and quality 0 https://Github.com/go-python/gpython/security
Insights https://Github.com/go-python/gpython/pulse
Code https://Github.com/go-python/gpython
Issues https://Github.com/go-python/gpython/issues
Pull requests https://Github.com/go-python/gpython/pulls
Actions https://Github.com/go-python/gpython/actions
Projects https://Github.com/go-python/gpython/projects
Wiki https://Github.com/go-python/gpython/wiki
Security and quality https://Github.com/go-python/gpython/security
Insights https://Github.com/go-python/gpython/pulse
Sign up for GitHub https://Github.com/signup?return_to=%2Fgo-python%2Fgpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://Github.com/login?return_to=%2Fgo-python%2Fgpython%2Fissues%2Fnew%2Fchoose
ncwhttps://Github.com/ncw
mainhttps://Github.com/go-python/gpython/tree/main
fix-257-RunSrchttps://Github.com/go-python/gpython/tree/fix-257-RunSrc
Conversation 0 https://Github.com/go-python/gpython/pull/258
Commits 1 https://Github.com/go-python/gpython/pull/258/commits
Checks 6 https://Github.com/go-python/gpython/pull/258/checks
Files changed https://Github.com/go-python/gpython/pull/258/files
Please reload this pagehttps://Github.com/go-python/gpython/pull/258/files
py: fix RunSrc to allow multiple top-level statements (#257) https://Github.com/go-python/gpython/pull/258/files#top
Show all changes 1 commit https://Github.com/go-python/gpython/pull/258/files
7f571f8 py: fix RunSrc to compile in ExecMode so multi-statement source works ncw Jul 3, 2026 https://Github.com/go-python/gpython/pull/258/commits/7f571f8b452c8c310f6004b429f050f3d84495ad
Clear filters https://Github.com/go-python/gpython/pull/258/files
Please reload this pagehttps://Github.com/go-python/gpython/pull/258/files
Please reload this pagehttps://Github.com/go-python/gpython/pull/258/files
run.go https://Github.com/go-python/gpython/pull/258/files#diff-b3f37e346e33b69ccce42245930069a302739986aabcb3d157ba1cf8618943e6
runsrc_test.go https://Github.com/go-python/gpython/pull/258/files#diff-0fa0b0708dd9431761e48acf5f8fef00f518d067b0948d52b8b25efd6a1af127
py/run.gohttps://Github.com/go-python/gpython/pull/258/files#diff-b3f37e346e33b69ccce42245930069a302739986aabcb3d157ba1cf8618943e6
View file https://Github.com/go-python/gpython/blob/7f571f8b452c8c310f6004b429f050f3d84495ad/py/run.go
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://Github.com/go-python/gpython/pull/258/{{ revealButtonHref }}
https://Github.com/go-python/gpython/pull/258/files#diff-b3f37e346e33b69ccce42245930069a302739986aabcb3d157ba1cf8618943e6
https://Github.com/go-python/gpython/pull/258/files#diff-b3f37e346e33b69ccce42245930069a302739986aabcb3d157ba1cf8618943e6
pytest/runsrc_test.gohttps://Github.com/go-python/gpython/pull/258/files#diff-0fa0b0708dd9431761e48acf5f8fef00f518d067b0948d52b8b25efd6a1af127
View file https://Github.com/go-python/gpython/blob/7f571f8b452c8c310f6004b429f050f3d84495ad/pytest/runsrc_test.go
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://Github.com/go-python/gpython/pull/258/{{ revealButtonHref }}
Please reload this pagehttps://Github.com/go-python/gpython/pull/258/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.