GeezerVison is showing github.com — gh-134551: Add t-strings support to pprint by loic-simon · Pull Request #134577 · python/cpython
Conversation
loic-simon
commented
May 23, 2025
•
edited by hugovk
Loading
Uh oh!
There was an error while loading. Please reload this page.
Handle formatting of Template and Interpolation types in pprint functions:
>>> from pprint import pp
>>> name = "World"
>>> pp(t"Hello {name}")
Template(strings=('Hello ', ''),
interpolations=(Interpolation('World', 'name', None, ''),))""")
Very straightforward, using existing PrettyPrinter helper methods.
To avoid slowing import time, I did not import Template and Interpolation from string.templatelib, but instead copied their (very simple) definition:
|
t = t"{0}" |
|
Template = type(t) |
|
Interpolation = type(t.interpolations[0]) |
|
del t |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
loic-simon
commented
May 23, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Not sure why test.test_tokenize.TestRoundtrip.test_random_files fails on test_pprint.py? If I replace t-strings by f-strings it pass, is it an issue with the test not handling t-strings? Or a real issue with tokenizer round-trippring and t-strings?
Edit: looks like a real problem, I have a MRE, opening an issue soon
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
hugovk
commented
Apr 13, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
I've updated this PR to fix the merge conflict, add support for the new expand=True from #136964, and add this to What's New.
>>> from pprint import pp
>>> name = "World"
>>> pp(t"Hello {name}")
Template(strings=('Hello ', ''),
interpolations=(Interpolation('World', 'name', None, ''),))
>>> pp(t"Hello {name}", expand=True)
Template(
strings=('Hello ', ''),
interpolations=(Interpolation('World', 'name', None, ''),),
)
|
davepeck reacted with heart emoji
loic-simon reacted with rocket emoji
All reactions
-
❤️
1 reaction
-
🚀
1 reaction
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ljfp
pushed a commit
to ljfp/cpython
that referenced
this pull request
Apr 25, 2026
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Reviewers
hugovk
hugovk approved these changes
AA-Turner
Awaiting requested review from AA-Turner
AA-Turner is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|