@@ -209,7 +209,7 @@ Like ``Template``, it is a new class found in the :mod:`!string.templatelib` mod
209209 def __new__ (
210210 cls ,
211211 value : object ,
212- expression : str ,
212+ expression : str = " " ,
213213 conversion : Literal[" a" , " r" , " s" ] | None = None ,
214214 format_spec : str = " " ,
215215 ):
@@ -226,14 +226,20 @@ The ``value`` attribute is the evaluated result of the interpolation:
226226 template = t" Hello {name} "
227227 assert template.interpolations[0 ].value == " World"
228228
229- The ``expression `` attribute is the *original text * of the interpolation:
229+ When interpolations are created from a template string literal, the
230+ ``expression `` attribute contains the *original text * of the interpolation:
230231
231232.. code-block :: python
232233
233234 name = " World"
234235 template = t" Hello {name} "
235236 assert template.interpolations[0 ].expression == " name"
236237
238+ When developers explicitly construct an ``Interpolation ``, they may optionally
239+ provide a value for the ``expression `` attribute. Even though it is stored as
240+ a string, this *should * be a valid Python expression. If no value is provided,
241+ the ``expression `` attribute defaults to the empty string (``"" ``).
242+
237243We expect that the ``expression `` attribute will not be used in most template
238244processing code. It is provided for completeness and for use in debugging and
239245introspection. See both the `Common Patterns Seen in Processing Templates `_
@@ -462,7 +468,9 @@ The debug specifier, ``=``, is supported in template strings and behaves similar
462468to how it behaves in f-strings, though due to limitations of the implementation
463469there is a slight difference.
464470
465- In particular, ``t'{value=}' `` is treated as ``t'value={value!r}' ``:
471+ In particular, ``t'{value=}' `` is treated as ``t'value={value!r}' ``. The first
472+ static string is rewritten from ``"" `` to ``"value=" `` and the ``conversion ``
473+ defaults to ``r ``:
466474
467475.. code-block :: python
468476
@@ -472,8 +480,11 @@ In particular, ``t'{value=}'`` is treated as ``t'value={value!r}'``:
472480 assert template.interpolations[0 ].value == " World"
473481 assert template.interpolations[0 ].conversion == " r"
474482
475- If a separate format string is also provided, ``t'{value=:fmt} `` is treated
476- instead as ``t'value={value!s:fmt}' ``.
483+ If a conversion is explicitly provided, it is kept: ``t'{value=!s}' ``
484+ is treated as ``t'value={value!s}' ``.
485+
486+ If a format string is provided without a conversion, the ``conversion ``
487+ is set to ``None ``: ``t'{value=:fmt}' `` is treated as ``t'value={value:fmt}' ``.
477488
478489Whitespace is preserved in the debug specifier, so ``t'{value = }' `` is
479490treated as ``t'value = {value!r}' ``.
@@ -549,7 +560,7 @@ Examples
549560========
550561
551562All examples in this section of the PEP have fully tested reference implementations
552- available in the public `pep750-examples <https://github.com/davepeck /pep750-examples >`_
563+ available in the public `pep750-examples <https://github.com/t-strings /pep750-examples >`_
553564git repository.
554565
555566
@@ -602,8 +613,8 @@ specifiers like ``:.2f``. The full code is fairly simple:
602613
603614 See `fstring.py `__ and `test_fstring.py `__.
604615
605- __ https://github.com/davepeck /pep750-examples/blob/main/pep/fstring.py
606- __ https://github.com/davepeck /pep750-examples/blob/main/pep/test_fstring.py
616+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/fstring.py
617+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/test_fstring.py
607618
608619
609620Example: Structured Logging
@@ -775,8 +786,8 @@ logging:
775786
776787 See `logging.py `__ and `test_logging.py `__.
777788
778- __ https://github.com/davepeck /pep750-examples/blob/main/pep/logging.py
779- __ https://github.com/davepeck /pep750-examples/blob/main/pep/test_logging.py
789+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/logging.py
790+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/test_logging.py
780791
781792
782793Example: HTML Templating
@@ -785,7 +796,7 @@ Example: HTML Templating
785796This PEP contains several short HTML templating examples. It turns out that the
786797"hypothetical" ``html() `` function mentioned in the `Motivation `_ section
787798(and a few other places in this PEP) exists and is available in the
788- `pep750-examples repository <https://github.com/davepeck /pep750-examples/ >`_.
799+ `pep750-examples repository <https://github.com/t-strings /pep750-examples/ >`_.
789800If you're thinking about parsing a complex grammar with template strings, we
790801hope you'll find it useful.
791802
@@ -1081,8 +1092,8 @@ and is able to ``await`` an interpolation's value.
10811092
10821093 See `afstring.py `__ and `test_afstring.py `__.
10831094
1084- __ https://github.com/davepeck /pep750-examples/blob/main/pep/afstring.py
1085- __ https://github.com/davepeck /pep750-examples/blob/main/pep/test_afstring.py
1095+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/afstring.py
1096+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/test_afstring.py
10861097
10871098
10881099Approaches to Template Reuse
@@ -1157,16 +1168,16 @@ which supports the full grammar of format strings.
11571168
11581169 See `format.py `__ and `test_format.py `__.
11591170
1160- __ https://github.com/davepeck /pep750-examples/blob/main/pep/format.py
1161- __ https://github.com/davepeck /pep750-examples/blob/main/pep/test_format.py
1171+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/format.py
1172+ __ https://github.com/t-strings /pep750-examples/blob/main/pep/test_format.py
11621173
11631174
11641175Reference Implementation
11651176========================
11661177
11671178A CPython implementation of PEP 750 is `available <https://github.com/lysnikolaou/cpython/tree/tstrings >`_.
11681179
1169- There is also a public repository of `examples and tests <https://github.com/davepeck /pep750-examples >`_
1180+ There is also a public repository of `examples and tests <https://github.com/t-strings /pep750-examples >`_
11701181built around the reference implementation. If you're interested in playing with
11711182template strings, this repository is a great place to start.
11721183
0 commit comments