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-132661: Document t-strings and `templatelib` by davepeck · Pull Request #135229 · python/cpython

Conversation

@davepeck

@davepeck davepeck commented Jun 6, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This PR adds documentation for t-strings, including:

  • Document string.templatelib in the Library reference section
  • Add new t-string details to lexical-analysis.rst
  • Add AST nodes to the ast docs
  • Add BUILD_INTERPOLATION and BUILD_TEMPLATE to the dis docs
  • Update the PEP 292 section Template strings section of Doc/library/string.rst to clarify that this is unrelated to t-strings
  • Add a t-strings section to "fancier input/output formatting", after the f-strings section
  • Glossary

We also have an issue tracking our original list of PEP 750 documentation tasks.

  • Issue: Implement PEP 750 – Template Strings #132661

📚 Documentation preview 📚: https://cpython-previews--135229.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

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

All reactions
@davepeck
Initial commit.
5a8dbfa
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Jun 6, 2025
@github-project-automation github-project-automation Bot added this to Docs PRs Jun 6, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Jun 6, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jun 6, 2025
Implement PEP 750 – Template Strings #132661
Closed
pauleveritt and others added 10 commits June 8, 2025 10:49
@pauleveritt
Make clear the preceding discussion about t-strings creating an insta…
09a1e9e
…nce of `templatelib.Template`.
@pauleveritt
Get the import order sorted.
ec44c2b
@pauleveritt
Correct the Interpolation() calls.
d8904b6
@pauleveritt
Add documentation for Interpolation.
550aa6d
@pauleveritt
Convert to use Sphinx modifiers for type, returns, and rtype.
a20e058
@pauleveritt
Add an entry to the glossary.
1f30739
@pauleveritt
Find any occurrences of f-strings that should also mention t-strings.
d935dd6
@davepeck
Fix doctests for str.templatelib
1e47362
@davepeck
Start writing the t-strings part of lexical analysis
7b660be
@davepeck
Merge branch 'main' into docs/pep750-first-pass
00a535d
hugovk
hugovk reviewed Jun 13, 2025
View reviewed changes
Comment thread Doc/reference/lexical_analysis.rst Resolved

Uh oh!

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

Comment thread Doc/reference/lexical_analysis.rst Resolved

Uh oh!

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

Comment thread Doc/reference/lexical_analysis.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

@davepeck

davepeck commented Jun 13, 2025

Copy link
Copy Markdown
Contributor Author

@hugovk Thank you for the review and the helpful early feedback! Useful to know about linking.

(FWIW this is very early stage still, so I expect plenty more linting and other issues that we'll eventually resolve.)

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

davepeck added 3 commits June 17, 2025 17:22
@davepeck
Fix lint issues
fcd74e6
@davepeck
Fix further sphinx warnings
a796f5d
@davepeck
More!
21d337c
@brianschubert brianschubert mentioned this pull request Jun 22, 2025
No documentation of string.templatelib #135804
Closed
davepeck added 3 commits June 26, 2025 13:02
@davepeck
Merge branch 'main' into docs/pep750-first-pass
d043381
@davepeck
Wrap up lexical analysis updates... I think?
9a0a301
@davepeck
Document the new AST nodes (TemplateStr and Interpolation)
f2e5ca4
@davepeck davepeck mentioned this pull request Jun 26, 2025
Write the official cpython documentation for t-strings t-strings/help#2
Open
10 of 11 tasks
@davepeck
First pass at documenting BUILD_TEMPLATE and BUILD_INTERPOLATION
8484b81
encukou
encukou reviewed Jun 27, 2025
View reviewed changes
Comment thread Doc/reference/lexical_analysis.rst Resolved

Uh oh!

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

encukou
encukou reviewed Jun 27, 2025
View reviewed changes
Comment thread Doc/glossary.rst Resolved

Uh oh!

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

@davepeck davepeck mentioned this pull request Jun 27, 2025
gh-135676: Lexical analysis: Reword String literals and related sections #135942
Merged
@hugovk

hugovk commented Jul 20, 2025

Copy link
Copy Markdown
Member

At EuroPython sprints, @AA-Turner says he still wants to review this.

As release manager, I've given him until the first release candidate on Tuesday when I'll merge this. We can always make further updates, but let's at least have something for RC1.

davepeck and treyhunner reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@picnixz
picnixz self-requested a review July 20, 2025 10:44
picnixz
picnixz reviewed Jul 20, 2025
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would adivse against using !class.attr in Sphinx roles as this would also make class being rendered, and instead, I suggest using regular double-backticks instead or use attr + ~, although this would create a link that we may not want it.

On Sphinx' side, I think we should really do something for supporting !~ because it becomes annoying to lose semantics.

Sorry, something went wrong.

Uh oh!

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

davepeck reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/library/string.templatelib.rst Resolved

Uh oh!

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

Comment thread Doc/tutorial/inputoutput.rst Resolved

Uh oh!

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

davepeck added 5 commits July 21, 2025 10:58
@davepeck
Merge branch 'main' into docs/pep750-first-pass
9070840
@davepeck
Revert unrelated change in inputoutput.rst
5af0434
@davepeck
"shallow immutable" -> "immutable"
437320d
@davepeck
Use :type:, not :rtype:, for attributes.
d69d8e0
@davepeck
'is always' -> 'always has'
ae6f072
@davepeck

davepeck commented Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @picnixz for the feedback! Think I took care of all your suggestions.

On Sphinx' side, I think we should really do something for supporting !~ because it becomes annoying to lose semantics.

That would be really nice!

All reactions

Sorry, something went wrong.

Uh oh!

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

@davepeck
Merge branch 'main' into docs/pep750-first-pass
6446762
picnixz
picnixz approved these changes Jul 21, 2025
View reviewed changes

@picnixz picnixz left a comment •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a sphinx maintainer I'm happy to see that directives are used but I fear that it could make the text a bit too "heavy to read". My main concern is that the theme we use actually creates lots of boxes and only a few online pages relies on directives, and prefer indicating the parameter type or the attribute type in the text directly (for instance for "expression", we would rather say "The text of a valid Python expression as a str, possibly empty".

I won't block this PR because of this choice as it's an entirely new page but in the future we may want to remove parameter boxes from the documentation.

If we don't have time until the RC release to fix the links/refs/inline code, we can do it later. For the content itself, I'm mostly good.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst

.. attribute:: expression

:returns: The text of a valid Python expression, or an empty string.

@picnixz picnixz Jul 21, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for :returns: You can write the attribute directive body the same way you did for Template.interpolations for instance.

Sorry, something went wrong.

Uh oh!

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

All reactions
AA-Turner
AA-Turner reviewed Jul 22, 2025
View reviewed changes

@AA-Turner AA-Turner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I abandoned my review and started over as various things had gotten out of date. I'll apply the simple fixes manually for time.

A

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/glossary.rst
@@ -462,7 +462,7 @@ Glossary
core and with user code.

f-string

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f-string
f-string
f-strings

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/glossary.rst

See also :term:`borrowed reference`.

t-string

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t-string
t-string
t-strings

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/ast.rst
Comment on lines +292 to +294
* 115 (``ord('s')``): ``!s`` string formatting
* 114 (``ord('r')``): ``!r`` repr formatting
* 97 (``ord('a')``): ``!a`` ASCII formatting

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 115 (``ord('s')``): ``!s`` string formatting
* 114 (``ord('r')``): ``!r`` repr formatting
* 97 (``ord('a')``): ``!a`` ASCII formatting
* 97: ``!a`` :func:`ASCII <ascii>` formatting (``ord('a')``)
* 114: ``!r`` :func:`repr` formatting (``ord('r')``)
* 115: ``!s`` :func:`string <str>` formatting (``ord('s')``)

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/ast.rst
Comment on lines +328 to +331
.. class:: TemplateStr(values)

A t-string, comprising a series of :class:`Interpolation` and :class:`Constant`
nodes.

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note on AST node ordering

Suggested change
.. class:: TemplateStr(values)
A t-string, comprising a series of :class:`Interpolation` and :class:`Constant`
nodes.
.. class:: TemplateStr(values, /)
Node representing a template string literal, comprising a series of
:class:`Interpolation` and :class:`Constant` nodes.
These nodes may be any order, and do not need to be interleaved.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/ast.rst
.. versionadded:: 3.14


.. class:: Interpolation(value, str, conversion, format_spec)

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. class:: Interpolation(value, str, conversion, format_spec)
.. class:: Interpolation(value, str, conversion, format_spec=None)

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/reference/lexical_analysis.rst
Comment on lines +929 to +930
- Rather than evaluating to a ``str`` object, t-strings evaluate to a
:class:`~string.templatelib.Template` object from the

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Rather than evaluating to a ``str`` object, t-strings evaluate to a
:class:`~string.templatelib.Template` object from the
* Rather than evaluating to a ``str`` object, template string literals evaluate
to a :class:`~string.templatelib.Template` object from the

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/reference/lexical_analysis.rst
:class:`~string.templatelib.Template` object from the
:mod:`string.templatelib` module.

- The :func:`format` protocol is not used. Instead, the format specifier and

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The :func:`format` protocol is not used. Instead, the format specifier and
* The :func:`format` protocol is not used. Instead, the format specifier and

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/reference/lexical_analysis.rst
processes the resulting :class:`~string.templatelib.Template` object to
decide how to handle format specifiers and conversions.

- Format specifiers containing nested replacement fields are evaluated eagerly,

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Format specifiers containing nested replacement fields are evaluated eagerly,
* Format specifiers containing nested replacement fields are evaluated eagerly,

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/reference/lexical_analysis.rst
Comment on lines +943 to +944
attribute of the resulting :class:`!Interpolation` object; if ``precision``
is (for example) ``2``, the resulting format specifier will be ``'.2f'``.

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
attribute of the resulting :class:`!Interpolation` object; if ``precision``
is (for example) ``2``, the resulting format specifier will be ``'.2f'``.
attribute of the resulting :class:`!Interpolation` object.
For example, if ``precision`` is ``2``, the resulting format specifier
will be ``'.2f'``.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/reference/lexical_analysis.rst
attribute of the resulting :class:`!Interpolation` object; if ``precision``
is (for example) ``2``, the resulting format specifier will be ``'.2f'``.

- When the equal sign ``'='`` is provided in an interpolation expression, the

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- When the equal sign ``'='`` is provided in an interpolation expression, the
* When the equals sign ``'='`` is provided in an interpolation expression, the

Sorry, something went wrong.

Uh oh!

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

All reactions
@AA-Turner

AA-Turner commented Jul 22, 2025

Copy link
Copy Markdown
Member

@davepeck @lysnikolaou this PR is from an organisation fork (@t-strings), so we can't apply suggestions or push commits. Please would you be able to do so? Hugo wants to get this PR in before starting RC1 later today.

A

All reactions

Sorry, something went wrong.

Uh oh!

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

AA-Turner
AA-Turner reviewed Jul 22, 2025
View reviewed changes

@AA-Turner AA-Turner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part 2 (briefer as we can't apply suggestions)

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
.. seealso::

* :ref:`Format strings <f-strings>`
* :ref:`T-string literal syntax <t-strings>`

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* :ref:`T-string literal syntax <t-strings>`
* :ref:`Template string literal (t-string) syntax <t-strings>`

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst

* :ref:`Format strings <f-strings>`
* :ref:`T-string literal syntax <t-strings>`

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* :pep:`750`

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
Comment on lines +24 to +30
Template strings are a formatting mechanism that allows for deep control over
how strings are processed. You can create templates using
:ref:`t-string literal syntax <t-strings>`, which is identical to
:ref:`f-string syntax <f-strings>` but uses a ``t`` instead of an ``f``.
While f-strings evaluate to ``str``, t-strings create a :class:`Template`
instance that gives you access to the static and interpolated (in curly braces)
parts of a string *before* they are combined.

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Template strings are a formatting mechanism that allows for deep control over
how strings are processed. You can create templates using
:ref:`t-string literal syntax <t-strings>`, which is identical to
:ref:`f-string syntax <f-strings>` but uses a ``t`` instead of an ``f``.
While f-strings evaluate to ``str``, t-strings create a :class:`Template`
instance that gives you access to the static and interpolated (in curly braces)
parts of a string *before* they are combined.
Template strings are a mechanism for custom string processing.
They have the full flexibility of Python's :ref:`f-strings`,
but return a :class:`Template` instance that gives access
to the static and interpolated (in curly braces) parts of a string
*before* they are combined.
To write a t-string, use a ``'t'`` prefix instead of an ``'f'``, like so:
.. code-block:: pycon
>>> pi = 3.14
>>> t't-strings are new in Python {pi!s}!'
Template(
strings=('t-strings are new in Python ', '!'),
interpolations=(Interpolation(3.14, 'pi', 's', ''),)
)

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
Comment on lines +38 to +42
The :class:`!Template` class describes the contents of a template string.

:class:`!Template` instances are immutable: their attributes cannot be
reassigned.

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The :class:`!Template` class describes the contents of a template string.
:class:`!Template` instances are immutable: their attributes cannot be
reassigned.
The :class:`!Template` class describes the contents of a template string.
It is immutable, meaning that attributes of a template cannot be reassigned.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
Comment on lines +45 to +57
Create a new :class:`!Template` object.

:param args: A mix of strings and :class:`Interpolation` instances in any order.
:type args: str | Interpolation

The most common way to create a :class:`!Template` instance is to use the
:ref:`t-string literal syntax <t-strings>`. This syntax is identical to that of
:ref:`f-strings <f-strings>` except that it uses a ``t`` instead of an ``f``:

>>> name = "World"
>>> template = t"Hello {name}!"
>>> type(template)
<class 'string.templatelib.Template'>

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved later; most users won't need to create Template objects by calling the class, but will need to know what the class is for and does. Perhaps you could separately document Template.__init__()?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
.. attribute:: values
:type: tuple[Any, ...]

A tuple of all interpolated values in the template.

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A tuple of all interpolated values in the template.
A tuple of the values of every interpolation in the template.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
Comment on lines +162 to +163
Iterate over the template, yielding each string and
:class:`Interpolation` in order.

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"in order" here I think could do with more exposition, or reference to the "proper" order of a Template

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
Comment on lines +205 to +217
Create a new :class:`!Interpolation` object.

:param value: The evaluated, in-scope result of the interpolation.
:type value: object

:param expression: The text of a valid Python expression, or an empty string.
:type expression: str

:param conversion: The optional :ref:`conversion <formatstrings>` to be used, one of r, s, and a.
:type conversion: ``Literal["a", "r", "s"] | None``

:param format_spec: An optional, arbitrary string used as the :ref:`format specification <formatspec>` to present the value.
:type format_spec: str

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with Template, I think direct construction should be moved to Interpolation.__init__()

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/string.templatelib.rst
Comment on lines +309 to +311
* ``'s'`` which calls :func:`str` on the value,
* ``'r'`` which calls :func:`repr`, and
* ``'a'`` which calls :func:`ascii`.

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the exclamation-mark forms for people doing a Ctrl-F search

Suggested change
* ``'s'`` which calls :func:`str` on the value,
* ``'r'`` which calls :func:`repr`, and
* ``'a'`` which calls :func:`ascii`.
* ``'s'`` which calls :func:`str` on the value (like ``!s``),
* ``'r'`` which calls :func:`repr` (like ``!r``), and
* ``'a'`` which calls :func:`ascii` (like ``!a``).

Sorry, something went wrong.

Uh oh!

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

blaisep reacted with hooray emoji
All reactions
  • 🎉 1 reaction
Comment thread Doc/library/string.templatelib.rst
Comment on lines +286 to +295
Interpolations support pattern matching, allowing you to match against
their attributes with the :ref:`match statement <match>`:

>>> from string.templatelib import Interpolation
>>> interpolation = Interpolation(3.0, "1 + 2", None, ".2f")
>>> match interpolation:
... case Interpolation(value, expression, conversion, format_spec):
... print(value, expression, conversion, format_spec)
...
3.0 1 + 2 None .2f

@AA-Turner AA-Turner Jul 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved up into the main body description of Interpolation

Sorry, something went wrong.

Uh oh!

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

All reactions
@hugovk

hugovk commented Jul 22, 2025

Copy link
Copy Markdown
Member

Let's merge and add the updates in a followup. Thanks all! 🫖🧵📚🚀

davepeck reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

@hugovk
hugovk merged commit 22c8658 into python:main Jul 22, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Jul 22, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 22, 2025
@hugovk hugovk added the needs backport to 3.14 bugs and security fixes label Jul 22, 2025
@miss-islington-app

miss-islington-app Bot commented Jul 22, 2025

Copy link
Copy Markdown

Thanks @davepeck for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 22, 2025
@davepeck @encukou
@hugovk @loic-simon @pauleveritt @miss-islington
pythongh-132661: Document t-strings and templatelib (pythonGH-135229)
17f5989
(cherry picked from commit 22c8658)

Co-authored-by: Dave Peck <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: pauleveritt <[email protected]>
@bedevere-app

bedevere-app Bot commented Jul 22, 2025

Copy link
Copy Markdown

GH-136974 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 22, 2025
hugovk added a commit that referenced this pull request Jul 22, 2025
@miss-islington @davepeck
@encukou @hugovk @loic-simon @pauleveritt @lysnikolaou
[3.14] gh-132661: Document t-strings and templatelib (GH-135229) (#…
c59a60b
…136974)

Co-authored-by: Dave Peck <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: pauleveritt <[email protected]>
Co-authored-by: Lysandros Nikolaou <[email protected]>
@AA-Turner AA-Turner mentioned this pull request Jul 22, 2025
gh-132661: PEP 750 documentation: second pass #137020
Merged
@AA-Turner

AA-Turner commented Jul 22, 2025

Copy link
Copy Markdown
Member

See #137020 for the promised followup.

A

davepeck and encukou reacted with hooray emoji hugovk reacted with rocket emoji
All reactions
  • 🎉 2 reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@davepeck davepeck mentioned this pull request Jul 29, 2025
gh-132661: docs: add a t-string tutorial #137213
Closed
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@davepeck @encukou
@hugovk @loic-simon @pauleveritt @taegyunkim
pythongh-132661: Document t-strings and templatelib (python#135229)
fa34305
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: pauleveritt <[email protected]>
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
@davepeck @encukou
@hugovk @loic-simon @pauleveritt @Agent-Hellboy
pythongh-132661: Document t-strings and templatelib (python#135229)
47c6a72
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: pauleveritt <[email protected]>
kumaraditya303 pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2025
@miss-islington @davepeck
@encukou @hugovk @loic-simon @pauleveritt @lysnikolaou @kumaraditya303
[3.14] pythongh-132661: Document t-strings and templatelib (pythonG…
558b331
…H-135229) (python#136974)

Co-authored-by: Dave Peck <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: pauleveritt <[email protected]>
Co-authored-by: Lysandros Nikolaou <[email protected]>
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 AA-Turner left review comments
@encukou encukou encukou approved these changes
@picnixz picnixz picnixz approved these changes
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
+2 more reviewers
@koxudaxi koxudaxi koxudaxi left review comments
@loic-simon loic-simon loic-simon left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news

Projects

Docs PRs
Status: Done

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.

10 participants

@davepeck @treyhunner @blaisep @encukou @hugovk @AA-Turner @koxudaxi @picnixz @loic-simon @pauleveritt
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.