FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

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

Repository navigation

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

Merged
hugovk merged 9 commits into
python:mainfrom
loic-simon:add-templates-to-pprint
Apr 14, 2026
Merged

hugovk merged 9 commits into
python:mainfrom
loic-simon:add-templates-to-pprint

Conversation

loic-simon commented May 23, 2025 •
edited by hugovk
Loading

Copy link
Copy Markdown
Contributor

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

loic-simon commented May 23, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

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

Comment thread Lib/test/.ruff.toml Outdated
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
AlexWaygood removed their request for review June 16, 2025 22:36

hugovk commented Apr 13, 2026 •
edited
Loading

Copy link
Copy Markdown
Member

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, ''),),
)

hugovk merged commit 74a4f8c into python:main Apr 14, 2026
55 checks passed
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL