KEMBAR78
gh-134551: Add t-strings support to pprint by loic-simon · Pull Request #134577 · python/cpython · GitHub
Skip to content

Conversation

@loic-simon
Copy link
Contributor

@loic-simon loic-simon commented May 23, 2025

Handle formatting of Template and Interpolation types in pprint functions:

>>> from pprint import pp
>>> name = "World"
>>> pp(t"Hello {World}")
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

@loic-simon
Copy link
Contributor Author

loic-simon commented May 23, 2025

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

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@AlexWaygood AlexWaygood removed their request for review June 16, 2025 22:36
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.

2 participants