GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-134551: Add t-strings support to pprint by loic-simon · Pull Request #134577 · python/cpython

Conversation

@loic-simon

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

Uh oh!

There was an error while loading. Please reload this page.

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:

cpython/Lib/string/templatelib.py

Lines 8 to 11 in 99a9ab1

t = t"{0}"
Template = type(t)
Interpolation = type(t.interpolations[0])
del t

  • Issue: Add support for Template type (t-strings) to pprint #134551

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@loic-simon
Add Template / Interpolation formatting to pprint
628dc27
@bedevere-app bedevere-app Bot mentioned this pull request May 23, 2025
Add support for Template type (t-strings) to pprint #134551
Closed
@bedevere-app bedevere-app Bot added the awaiting review label May 23, 2025
blurb-it Bot and others added 3 commits May 23, 2025 10:28
@blurb-it
📜🤖 Added by blurb_it.
f14f7ad
@loic-simon
Merge branch 'python:main' into add-templates-to-pprint
9655e28
@loic-simon
Exclude test_pprint from ruff formatting
9a7a523
@loic-simon
loic-simon requested review from AA-Turner, AlexWaygood and hugovk as code owners May 23, 2025 12:02
@loic-simon

loic-simon commented May 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon loic-simon mentioned this pull request May 23, 2025
untokenize() round-trip fails for t-strings (with only type + string) #134582
Closed
hugovk
hugovk reviewed May 23, 2025
View reviewed changes
Comment thread Lib/test/.ruff.toml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon @hugovk
Fix names sorting in Lib/test/.ruff.toml
93380b5
Co-authored-by: Hugo van Kemenade <[email protected]>
@AlexWaygood
AlexWaygood removed their request for review June 16, 2025 22:36
hugovk added 4 commits March 24, 2026 21:27
@hugovk
Merge branch 'main' into add-templates-to-pprint
2f27d21
@hugovk
Merge remote-tracking branch 'upstream/main' into add-templates-to-pp…
12c9433
…rint
@hugovk
Add t-string support to pprint with expand=True
507bf30
@hugovk
Add to What's New
a486838
@hugovk

hugovk commented Apr 13, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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

hugovk
hugovk approved these changes Apr 13, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Apr 13, 2026
@hugovk
hugovk merged commit 74a4f8c into python:main Apr 14, 2026
55 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 14, 2026
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@loic-simon @hugovk
@blurb-it @ljfp
pythongh-134551: Add t-strings support to pprint (python#134577)
e3bf7d2
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hugovk hugovk hugovk approved these changes
@AA-Turner 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

Labels

None yet

Projects

None yet

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.

2 participants

@loic-simon @hugovk
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.