René's URL Explorer Experiment


Title: Interpolation.expression drops trailing whitespace despite documentation saying it includes any whitespace · Issue #154719 · python/cpython · GitHub

Open Graph Title: Interpolation.expression drops trailing whitespace despite documentation saying it includes any whitespace · Issue #154719 · python/cpython

X Title: Interpolation.expression drops trailing whitespace despite documentation saying it includes any whitespace · Issue #154719 · python/cpython

Description: Bug report Bug description: For t-string literals, Interpolation.expression preserves whitespace after the opening {, but removes whitespace immediately before the closing }. This appears inconsistent with the string.templatelib document...

Open Graph Description: Bug report Bug description: For t-string literals, Interpolation.expression preserves whitespace after the opening {, but removes whitespace immediately before the closing }. This appears inconsist...

X Description: Bug report Bug description: For t-string literals, Interpolation.expression preserves whitespace after the opening {, but removes whitespace immediately before the closing }. This appears inconsist...

Opengraph URL: https://github.com/python/cpython/issues/154719

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Interpolation.expression drops trailing whitespace despite documentation saying it includes any whitespace","articleBody":"# Bug report\n\n### Bug description:\n\nFor t-string literals, `Interpolation.expression` preserves whitespace after the opening `{`, but removes whitespace immediately before the closing `}`.\n\nThis appears inconsistent with the `string.templatelib` documentation, which states that, for interpolations created from t-string literals, expression contains the expression text inside the curly braces, including any whitespace.\n\n## Minimal reproducer\n\n```python\nx = 42\n\ncases = [\n    t\"{x}\",\n    t\"{x }\",\n    t\"{ x}\",\n    t\"{ x }\",\n    t\"{  x  }\",\n    t\"\"\"{\n  x\n}\"\"\",\n]\n\nfor template in cases:\n    print(repr(template.interpolations[0].expression))\n```\n\n## Actual behavior\n\nOn CPython main commit b86a41c:\n```text\n'x'\n'x'\n' x'\n' x'\n'  x'\n'\\n  x'\n```\nWhitespace following { is preserved, but whitespace before } is removed.\n\n## Expected behavior\n\nBased on the current documentation, I expected:\n```text\n'x'\n'x '\n' x'\n' x '\n'  x  '\n'\\n  x\\n'\n```\nIn particular:\n```text\nt\"{x }\".interpolations[0].expression == \"x \"\nt\"{ x }\".interpolations[0].expression == \" x \"\nt\"{  x  }\".interpolations[0].expression == \"  x  \"\n```\n\n## Possible cause\n\nA possible cause is the way the lexer reconstructs interpolation source text in `Parser/lexer/string.c`.\n\n`_PyLexer_update_ftstring_expr()` records `last_expr_end` when it reaches the closing `}`, `!`, or `:` token:\n```c\ncase '}':\ncase '!':\n    tok_mode->last_expr_end = strlen(tok->start);\n    break;\ncase ':':\n    if (tok_mode->last_expr_end == -1) {\n        tok_mode->last_expr_end = strlen(tok->start);\n    }\n    break;\n```\n`_PyLexer_set_ftstring_expr()` then creates the metadata from:\n```c\ntok_mode->last_expr_buffer,\ntok_mode->last_expr_size - tok_mode->last_expr_end\n```\nThis appears to remove the suffix represented by `last_expr_end`. In the ordinary `}` case, that suffix seems to include whitespace immediately before the closing brace, while whitespace immediately after the opening brace remains in `last_expr_buffer`.\n\nThat would explain the observed asymmetry:\n```text\nt\"{ x }\"  -> \" x\"\n\nleading whitespace preserved\ntrailing whitespace removed\n```\nThis is only a proposed cause based on the observed behavior and a source-code review.\n\n### CPython versions tested on:\n\n3.16, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154736\n* gh-154762\n* gh-157392\n* gh-157394\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/kid-lxy","@type":"Person","name":"kid-lxy"},"datePublished":"2026-07-26T07:26:13Z","url":"https://github.com/python/cpython/issues/154719"}

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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:db657e16-d639-5325-6ad1-8e62e7e80c2f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8AAC:2270F4:36F3195:48DB2CB:6B020795
html-safe-noncea961b69964f4ff5e538a265f08311f6b3be56c36514540c80894f8c2c1582d59
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QUFDOjIyNzBGNDozNkYzMTk1OjQ4REIyQ0I6NkIwMjA3OTUiLCJ2aXNpdG9yX2lkIjoiMTE0MTc5MDYwNjM3Mzg3NzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac6240dc78dbd378e5fc71f7b07163716a12d19ee946d546350ab50c9f482c5635
hovercard-subject-tagissue:4979585664
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154719/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7c729f6f5dea4c3b1e761cf12055df71c3a603210422031748d73efb1de3d3d0/python/cpython/issues/154719
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7c729f6f5dea4c3b1e761cf12055df71c3a603210422031748d73efb1de3d3d0/python/cpython/issues/154719
og:image:altBug report Bug description: For t-string literals, Interpolation.expression preserves whitespace after the opening {, but removes whitespace immediately before the closing }. This appears inconsist...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekid-lxy
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/154719#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F154719
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%2Fissues%2F154719
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/154719
Reloadhttps://github.com/python/cpython/issues/154719
Reloadhttps://github.com/python/cpython/issues/154719
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
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154719
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154719
Interpolation.expression drops trailing whitespace despite documentation saying it includes any whitespacehttps://github.com/python/cpython/issues/154719#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-parserhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-parser%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/kid-lxy
kid-lxyhttps://github.com/kid-lxy
on Jul 26, 2026https://github.com/python/cpython/issues/154719#issue-4979585664
b86a41chttps://github.com/python/cpython/commit/b86a41cbf631c959d274ad6180cf0a0ac6f6e180
gh-154719: Preserve trailing whitespace in t-string interpolation expressions #154736https://github.com/python/cpython/pull/154736
gh-154719: Preserve trailing whitespace in t-string interpolation expressions #154762https://github.com/python/cpython/pull/154762
[3.14] gh-154719: Preserve trailing whitespace in t-string interpolation expressions (#154762) #157392https://github.com/python/cpython/pull/157392
[3.15] gh-154719: Preserve trailing whitespace in t-string interpolation expressions (#154762) #157394https://github.com/python/cpython/pull/157394
kid-lxyhttps://github.com/kid-lxy
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Jul 26, 2026https://github.com/python/cpython/issues/154719#event-28493690471
picnixzhttps://github.com/picnixz
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-parserhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-parser%22
on Jul 26, 2026https://github.com/python/cpython/issues/154719#event-28493793746
lpyu001https://github.com/lpyu001
on Jul 26, 2026https://github.com/python/cpython/issues/154719#event-28499091517
pythongh-154719: Preserve trailing whitespace in t-string interpolati…https://github.com/lpyu001/cpython/commit/3cfd699519cc058025c1863998e969128b8b2fe3
pythongh-154719https://github.com/python/cpython/issues/154719
3cfd699https://github.com/lpyu001/cpython/commit/3cfd699519cc058025c1863998e969128b8b2fe3
pablogsalhttps://github.com/pablogsal
on Sep 13, 2026https://github.com/python/cpython/issues/154719#event-31037490290
gh-154719: Preserve trailing whitespace in t-string interpolation exp…https://github.com/python/cpython/commit/1a703ab9e6a050b40c469788ec7758713c6bf62b
gh-154719https://github.com/python/cpython/issues/154719
1a703abhttps://github.com/python/cpython/commit/1a703ab9e6a050b40c469788ec7758713c6bf62b
[3.14] gh-154719: Preserve trailing whitespace in t-string interpolat…https://github.com/python/cpython/commit/af0798e4f38f86696ee5eea6dcfa633ca32e43bd
gh-154719https://github.com/python/cpython/issues/154719
af0798ehttps://github.com/python/cpython/commit/af0798e4f38f86696ee5eea6dcfa633ca32e43bd
[3.15] gh-154719: Preserve trailing whitespace in t-string interpolat…https://github.com/python/cpython/commit/871bd46968e65777a04f88676f372ec99936fda3
gh-154719https://github.com/python/cpython/issues/154719
871bd46https://github.com/python/cpython/commit/871bd46968e65777a04f88676f372ec99936fda3
pablogsalhttps://github.com/pablogsal
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 13, 2026https://github.com/python/cpython/issues/154719#event-31053699611
johnslavikhttps://github.com/johnslavik
on Sep 14, 2026https://github.com/python/cpython/issues/154719#event-31099061263
pythongh-154719: Preserve trailing whitespace in t-string interpolati…https://github.com/johnslavik/cpython/commit/7931e95be79cf1d344ef17077b5215cb92f81bb3
pythongh-154719https://github.com/python/cpython/issues/154719
7931e95https://github.com/johnslavik/cpython/commit/7931e95be79cf1d344ef17077b5215cb92f81bb3
ArneshBanerjeehttps://github.com/ArneshBanerjee
on Sep 26, 2026https://github.com/python/cpython/issues/154719#event-31881317831
[3.13] pythongh-154711: Strip comments after escaped quotes in f-stri…https://github.com/ArneshBanerjee/cpython/commit/2877218adf4fd29bbfb8bae2b9617483de56ffbb
pythongh-154711https://github.com/python/cpython/issues/154711
2877218https://github.com/ArneshBanerjee/cpython/commit/2877218adf4fd29bbfb8bae2b9617483de56ffbb
pablogsalhttps://github.com/pablogsal
on Sep 29, 2026https://github.com/python/cpython/issues/154719#event-32119976314
[3.13] gh-154711: Strip comments after escaped quotes in f-string deb…https://github.com/python/cpython/commit/4192eadc82226f55f0fd1e12ab27aeb5c51631fc
gh-154711https://github.com/python/cpython/issues/154711
4192eadhttps://github.com/python/cpython/commit/4192eadc82226f55f0fd1e12ab27aeb5c51631fc
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/154719
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/154719
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-parserhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-parser%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
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.