Skip to content

gh-134551: Add t-strings support to pprint #134577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

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>
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy