@@ -24,7 +24,7 @@ Template strings
2424Template strings are a mechanism for custom string processing.
2525They have the full flexibility of Python's :ref: `f-strings `,
2626but return a :class: `Template ` instance that gives access
27- to the static and interpolated (in curly braces ) parts of a string
27+ to the static and interpolated (in curly brackets ) parts of a string
2828*before * they are combined.
2929
3030To write a t-string, use a ``'t' `` prefix instead of an ``'f' ``, like so:
@@ -258,13 +258,16 @@ Types
258258 .. attribute :: expression
259259 :type: str
260260
261- The text of a valid Python expression, or an empty string.
261+ For interpolations created by t-string literals, :attr: `!expression `
262+ is the expression text found inside the curly brackets (``{ `` & ``} ``),
263+ including any whitespace, excluding the curly brackets themselves,
264+ and ending before the first ``! ``, ``: ``, or ``= `` if any is present.
265+ For manually created interpolations, :attr: `!expression ` is the arbitrary
266+ string provided when constructing the interpolation instance.
262267
263- The :attr: `.expression ` is the original text of the
264- interpolation's Python expression, if the interpolation was created
265- from a t-string literal. Developers creating interpolations manually
266- should either set this to an empty string or choose a suitable valid
267- Python expression.
268+ We recommend using valid Python expressions or the empty string for the
269+ ``expression `` field of manually created :class: `!Interpolation `
270+ instances, although this is not enforced at runtime.
268271
269272 >>> t' {1 + 2}' .interpolations[0 ].expression
270273 '1 + 2'
0 commit comments