Skip to content

gh-154719: Preserve trailing whitespace in t-string interpolation expressions#154736

Open
lpyu001 wants to merge 1 commit into
python:mainfrom
lpyu001:0726
Open

gh-154719: Preserve trailing whitespace in t-string interpolation expressions#154736
lpyu001 wants to merge 1 commit into
python:mainfrom
lpyu001:0726

Conversation

@lpyu001

@lpyu001 lpyu001 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Issue

Interpolation.expression preserved whitespace after the opening {, but removed whitespace immediately before }, !, or :. This was inconsistent with the documented behavior of preserving the expression text inside the braces.

Root cause

The lexer metadata already contained the trailing whitespace, but the parser unconditionally stripped trailing whitespace from every interpolation expression while handling debug expressions.

Solution

Preserve the lexer metadata unchanged for regular interpolations. For self-documenting expressions, remove only the debug = and whitespace after it, while preserving whitespace before it. Add tests covering regular, converted, formatted, debug, comparison, and multiline expressions.

@lpyu001 lpyu001 changed the title gh-154719: Preserve trailing whitespace in t-string interpolation exp… gh-154719: Preserve trailing whitespace in t-string interpolation expressions Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant