You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Interpolation.expression drops trailing whitespace despite documentation saying it includes any whitespace #154719
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 documentation, which states that, for interpolations created from t-string literals, expression contains the expression text inside the curly braces, including any whitespace.
Minimal reproducer
x=42cases= [
t"{x}",
t"{x }",
t"{ x}",
t"{ x }",
t"{ x }",
t"""{ x}""",
]
fortemplateincases:
print(repr(template.interpolations[0].expression))
This 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.
That would explain the observed asymmetry:
t"{ x }" -> " x"
leading whitespace preserved
trailing whitespace removed
This is only a proposed cause based on the observed behavior and a source-code review.
Activity
pythongh-154719: Preserve trailing whitespace in t-string interpolati…
gh-154719: Preserve trailing whitespace in t-string interpolation exp…
[3.14] gh-154719: Preserve trailing whitespace in t-string interpolat…
[3.15] gh-154719: Preserve trailing whitespace in t-string interpolat…
pythongh-154719: Preserve trailing whitespace in t-string interpolati…
[3.13] pythongh-154711: Strip comments after escaped quotes in f-stri…
[3.13] gh-154711: Strip comments after escaped quotes in f-string deb…