René's URL Explorer Experiment


Title: gh-122622: Add PyREPL simple_interact.statement_submitted_hook by edvilme · Pull Request #157241 · python/cpython · GitHub

Open Graph Title: gh-122622: Add PyREPL simple_interact.statement_submitted_hook by edvilme · Pull Request #157241 · python/cpython

X Title: gh-122622: Add PyREPL simple_interact.statement_submitted_hook by edvilme · Pull Request #157241 · python/cpython

Description: Supersedes #144724 Adds a statement_submitted_hook hook to _pyrepl.simple_interact that gets triggered after the user has submitted a statement (not necessarily a line) but before it is executed. Rationale This should be configurable by external tools such as IDEs who may want to perform an action before a statement is executed, such as displaying custom escape sequences for terminal integration, handling custom logging logic, performing analysis, etc. This hook should allow said tools to perform an action. Example (Timer) >>> import _pyrepl >>> import sys >>> import time >>> class PS1: ... start_time = None ... def reset_start_time(self): ... self.start_time = time.perf_counter() ... def __init__(self): ... _pyrepl.simple_interact.statement_submitted_hook = lambda x: self.reset_start_time() ... def __str__(self): ... end_time = time.perf_counter() ... time_delta = end_time - self.start_time ... return f"# Execution took {time_delta}s \n>>> " ... >>> sys.ps1 = PS1() >>> 1 + 1 2 # Execution took 0.0021207999670878053s >>> [i for i in range(100)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] # Execution took 0.003159299958497286s Example (VSCode) VS Code uses custom escape sequences to indicate when a command execution has started and finished. Here, the hook could be used to print an invisible escape sequence to the terminal. (Note that the example uses ### EXEC ### to represent it visually, but escape sequences are invisible) With error reporting Issue: gh-122622 AI Usage AI was used to help with merge conflicts

Open Graph Description: Supersedes #144724 Adds a statement_submitted_hook hook to _pyrepl.simple_interact that gets triggered after the user has submitted a statement (not necessarily a line) but before it is executed. R...

X Description: Supersedes #144724 Adds a statement_submitted_hook hook to _pyrepl.simple_interact that gets triggered after the user has submitted a statement (not necessarily a line) but before it is executed. R...

Opengraph URL: https://github.com/python/cpython/pull/157241

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:f7158df6-bcac-3f26-46a2-cd6eff46b22d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA352:128588:C2FB72:1196A58:6AFDAADC
html-safe-nonce49cdcbbd1a2017ef57133da0616c0273d5d2b84d19d77e9cc101afb5377a0bbd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzUyOjEyODU4ODpDMkZCNzI6MTE5NkE1ODo2QUZEQUFEQyIsInZpc2l0b3JfaWQiOiI0MTUxMTc1NjQ1MzEwNTkzNzU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac879e03f98163bf439f576a1f943c9b36e543e23f6b914c7ae82f423b56543053
hovercard-subject-tagpull_request:4490193277
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/python/cpython/pull/157241/files
twitter:imagehttps://avatars.githubusercontent.com/u/5952839?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5952839?s=400&v=4
og:image:altSupersedes #144724 Adds a statement_submitted_hook hook to _pyrepl.simple_interact that gets triggered after the user has submitted a statement (not necessarily a line) but before it is executed. R...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonebc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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
release0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/157241/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F157241%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F157241%2Ffiles
Sign uphttps://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=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/157241/files
Reloadhttps://github.com/python/cpython/pull/157241/files
Reloadhttps://github.com/python/cpython/pull/157241/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
edvilmehttps://github.com/edvilme
python:mainhttps://github.com/python/cpython/tree/main
edvilme:pyrepl-hookhttps://github.com/edvilme/cpython/tree/pyrepl-hook
Conversation 45 https://github.com/python/cpython/pull/157241
Commits 27 https://github.com/python/cpython/pull/157241/commits
Checks 59 https://github.com/python/cpython/pull/157241/checks
Files changed 4 https://github.com/python/cpython/pull/157241/files
gh-122622: Add PyREPL simple_interact.statement_submitted_hook https://github.com/python/cpython/pull/157241/files#top
Show all changes 27 commits https://github.com/python/cpython/pull/157241/files
4c18d3b gh-122622: Add PyREPL pre-execution hook edvilme Sep 9, 2026 https://github.com/python/cpython/pull/157241/commits/4c18d3bdc20fa2cebe82e74bd025917196f5aad4
b988e6f Add empty pre_execution_hook for feature detection edvilme Sep 9, 2026 https://github.com/python/cpython/pull/157241/commits/b988e6f700cea2b922789924e838780e20d9e3f5
7d9ddbf Update tests to verify no interference edvilme Sep 9, 2026 https://github.com/python/cpython/pull/157241/commits/7d9ddbfe93b02e0e82b4f8a3aa5e5d2a7ba1108e
ad17396 📜🤖 Added by blurb_it. blurb-it[bot] Sep 9, 2026 https://github.com/python/cpython/pull/157241/commits/ad17396240c154f653fb791696bd507d6efa6f75
0ef602c Update NEWS edvilme Sep 9, 2026 https://github.com/python/cpython/pull/157241/commits/0ef602cf42bee64714b25d8534e298fbccc2f72e
8ede9b2 Address feedback edvilme Sep 18, 2026 https://github.com/python/cpython/pull/157241/commits/8ede9b25b7a87032e155f4c30c3bda7beebfaa78
6d7dfe0 Address feedback edvilme Sep 19, 2026 https://github.com/python/cpython/pull/157241/commits/6d7dfe0f41bd65765d02af68a39134569430920d
d45c1d3 Merge branch 'main' into pyrepl-hook edvilme Sep 19, 2026 https://github.com/python/cpython/pull/157241/commits/d45c1d37cffed694545490f57e060cc1d9c60a8d
e1186d5 Show tracebakcs edvilme Sep 21, 2026 https://github.com/python/cpython/pull/157241/commits/e1186d5a306f956036e6a654477f5990d3dd39f0
f615af2 Add tests to make sure hook runs before exception edvilme Sep 23, 2026 https://github.com/python/cpython/pull/157241/commits/f615af20aaf30907002b962ec1591b1ba0b993e9
f766b48 Update comment edvilme Oct 13, 2026 https://github.com/python/cpython/pull/157241/commits/f766b486a70b7243b5ac52fbdd4388fe27d18134
a81c71a Fix incorrect comment edvilme Oct 13, 2026 https://github.com/python/cpython/pull/157241/commits/a81c71abe41d0c79cd8479497f87acf3d16b1b95
a98d37a Merge branch 'main' into pyrepl-hook edvilme Oct 28, 2026 https://github.com/python/cpython/pull/157241/commits/a98d37a4c31b7b84cca09c9ed07a8d2a75a42c6b
d948c28 Merge branch 'main' into pyrepl-hook brettcannon Oct 29, 2026 https://github.com/python/cpython/pull/157241/commits/d948c288cda3cdf37780a29211ac7b5c8cab3176
ce55702 Strip final indent from submitted hook edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/ce55702d0996be48af0215afa5252d334ffb02b4
8665769 Show traceback as a hook failure without modifying sys.last_* edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/866576906ce742246396097772fd151fb1fd0457
b7e9986 Simplify comment to remove example edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/b7e9986fc46e2913a32cf2e68841214be3301ebd
753ed83 Add tests for KeyboardInterrupt and SystemExit edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/753ed835c8c144c2e0329b5e40c0656d43051f86
d2a7a45 Add test for strip indentation edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/d2a7a45156163b561c71c86393fd721c6cd29eb2
ac8d177 Remove weak return value test edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/ac8d177f5c262ef1e72b4c99dbd0c46ab121682a
e28071a Add PTY test edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/e28071a0a0aa97f909a219daa94acfa3c4532d8d
d6cd848 Update tests edvilme Nov 3, 2026 https://github.com/python/cpython/pull/157241/commits/d6cd84868d4d70dc64f19e8d82517919842ad738
7be412f Update News entry edvilme Nov 17, 2026 https://github.com/python/cpython/pull/157241/commits/7be412f2c3a14fa029ba847c655d68fe6e098569
0ea14cd Do not call _strip_final_indent twice edvilme Nov 17, 2026 https://github.com/python/cpython/pull/157241/commits/0ea14cd82b9ccb2419e595d6748f21d252290122
8ea46f3 Rename to input_submitted_hook edvilme Nov 17, 2026 https://github.com/python/cpython/pull/157241/commits/8ea46f3e094099cb8f3e322f608035626c4029ab
c385c46 Added Exception clarification to comment edvilme Nov 17, 2026 https://github.com/python/cpython/pull/157241/commits/c385c465fa1b8a45307aeabadc5adf3248d20272
9d4fe71 Merge branch 'main' into pyrepl-hook edvilme Nov 17, 2026 https://github.com/python/cpython/pull/157241/commits/9d4fe713b5156a9008801b56b21f08764fb07256
Clear filters https://github.com/python/cpython/pull/157241/files
Please reload this pagehttps://github.com/python/cpython/pull/157241/files
Please reload this pagehttps://github.com/python/cpython/pull/157241/files
simple_interact.py https://github.com/python/cpython/pull/157241/files#diff-0b3e2aa3c0ebaa4ebd022d2d64ddf43235b1401a622f372ad87f4822f21674b4
test_interact.py https://github.com/python/cpython/pull/157241/files#diff-dba95d75350c3dbb6fc4f5d2687a51d45987e858e8a39f20e7096ac9b2136d89
test_pyrepl.py https://github.com/python/cpython/pull/157241/files#diff-527def17e95277d68de9ccbef2358e5b89aba5407163ff8d0777936bb3f3bfab
2026-09-09-23-15-03.gh-issue-122622.YfSSrl.rst https://github.com/python/cpython/pull/157241/files#diff-e1e6845514acba331333f82e4de01486cd8ca3529507554af3fcc42710b334f6
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L571
Lib/_pyrepl/simple_interact.pyhttps://github.com/python/cpython/pull/157241/files#diff-0b3e2aa3c0ebaa4ebd022d2d64ddf43235b1401a622f372ad87f4822f21674b4
View file https://github.com/python/cpython/blob/9d4fe713b5156a9008801b56b21f08764fb07256/Lib/_pyrepl/simple_interact.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157241/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157241/files#diff-0b3e2aa3c0ebaa4ebd022d2d64ddf43235b1401a622f372ad87f4822f21674b4
https://github.com/python/cpython/pull/157241/files#diff-0b3e2aa3c0ebaa4ebd022d2d64ddf43235b1401a622f372ad87f4822f21674b4
https://github.com/python/cpython/pull/157241/files#diff-0b3e2aa3c0ebaa4ebd022d2d64ddf43235b1401a622f372ad87f4822f21674b4
https://github.com/python/cpython/pull/157241/files#diff-0b3e2aa3c0ebaa4ebd022d2d64ddf43235b1401a622f372ad87f4822f21674b4
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L572
Lib/test/test_pyrepl/test_interact.pyhttps://github.com/python/cpython/pull/157241/files#diff-dba95d75350c3dbb6fc4f5d2687a51d45987e858e8a39f20e7096ac9b2136d89
View file https://github.com/python/cpython/blob/9d4fe713b5156a9008801b56b21f08764fb07256/Lib/test/test_pyrepl/test_interact.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157241/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157241/files#diff-dba95d75350c3dbb6fc4f5d2687a51d45987e858e8a39f20e7096ac9b2136d89
https://github.com/python/cpython/pull/157241/files#diff-dba95d75350c3dbb6fc4f5d2687a51d45987e858e8a39f20e7096ac9b2136d89
https://github.com/python/cpython/pull/157241/files#diff-dba95d75350c3dbb6fc4f5d2687a51d45987e858e8a39f20e7096ac9b2136d89
johnslavikhttps://github.com/johnslavik
Oct 31, 2026https://github.com/python/cpython/pull/157241/files#r4429475322
Please reload this pagehttps://github.com/python/cpython/pull/157241/files
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
cpython/Lib/test/test_pyrepl/test_pyrepl.pyhttps://github.com/python/cpython/blob/d948c288cda3cdf37780a29211ac7b5c8cab3176/Lib/test/test_pyrepl/test_pyrepl.py#L2482-L2492
d948c28https://github.com/python/cpython/commit/d948c288cda3cdf37780a29211ac7b5c8cab3176
Please reload this pagehttps://github.com/python/cpython/pull/157241/files
pablogsalhttps://github.com/pablogsal
Oct 31, 2026https://github.com/python/cpython/pull/157241/files#r4431591854
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/157241/files
edvilmehttps://github.com/edvilme
Nov 3, 2026https://github.com/python/cpython/pull/157241/files#r4461096692
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
e28071a0a0ahttps://github.com/python/cpython/commit/e28071a0a0aa97f909a219daa94acfa3c4532d8d
b7e9986fc46https://github.com/python/cpython/commit/b7e9986fc46e2913a32cf2e68841214be3301ebd
Please reload this pagehttps://github.com/python/cpython/pull/157241/files
johnslavikhttps://github.com/johnslavik
Nov 17, 2026https://github.com/python/cpython/pull/157241/files#r4600962723
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/157241/files
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L572
Lib/test/test_pyrepl/test_pyrepl.pyhttps://github.com/python/cpython/pull/157241/files#diff-527def17e95277d68de9ccbef2358e5b89aba5407163ff8d0777936bb3f3bfab
View file https://github.com/python/cpython/blob/9d4fe713b5156a9008801b56b21f08764fb07256/Lib/test/test_pyrepl/test_pyrepl.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157241/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157241/files#diff-527def17e95277d68de9ccbef2358e5b89aba5407163ff8d0777936bb3f3bfab
https://github.com/python/cpython/pull/157241/files#diff-527def17e95277d68de9ccbef2358e5b89aba5407163ff8d0777936bb3f3bfab
Misc/NEWS.d/next/Library/2026-09-09-23-15-03.gh-issue-122622.YfSSrl.rsthttps://github.com/python/cpython/pull/157241/files#diff-e1e6845514acba331333f82e4de01486cd8ca3529507554af3fcc42710b334f6
View file https://github.com/python/cpython/blob/9d4fe713b5156a9008801b56b21f08764fb07256/Misc/NEWS.d/next/Library/2026-09-09-23-15-03.gh-issue-122622.YfSSrl.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157241/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/157241/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.