Skip to content

Commit f6cb83c

Browse files
committed
Improve description of Interpolation.expression
1 parent 20d5494 commit f6cb83c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Doc/library/string.templatelib.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,14 @@ Types
258258
.. attribute:: expression
259259
:type: str
260260

261-
The text of a valid Python expression, or an empty string.
262-
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.
261+
For interpolations created from t-string literals, :attr:`!expression`
262+
is the source text found inside the curly braces, including any
263+
whitespace, but excluding the curly braces themselves. For manually
264+
created interpolations, :attr:`!expression` is an arbitrary string.
265+
266+
It is recommended that developers manually creating
267+
:class:`!Interpolation` instances use valid Python expressions or leave
268+
the string empty, but this is not enforced.
268269

269270
>>> t'{1 + 2}'.interpolations[0].expression
270271
'1 + 2'

0 commit comments

Comments
 (0)