@@ -289,9 +289,9 @@ Literals
289
289
* ``conversion `` is an integer:
290
290
291
291
* -1: no formatting
292
- * 115 (``ord('s ') ``): ``!s `` string formatting
293
- * 114 (``ord('r') ``): ``!r `` repr formatting
294
- * 97 (``ord('a ') ``): ``!a `` ASCII formatting
292
+ * 97 (``ord('a ') ``): ``!a `` :func: ` ASCII <ascii> ` formatting
293
+ * 114 (``ord('r') ``): ``!r `` :func: ` repr ` formatting
294
+ * 115 (``ord('s ') ``): ``!s `` :func: ` string <str> ` formatting
295
295
296
296
* ``format_spec `` is a :class: `JoinedStr ` node representing the formatting
297
297
of the value, or ``None `` if no format was specified. Both
@@ -325,14 +325,18 @@ Literals
325
325
Constant(value='.3')]))]))
326
326
327
327
328
- .. class :: TemplateStr(values)
328
+ .. class :: TemplateStr(values, / )
329
329
330
- A t-string, comprising a series of :class: `Interpolation ` and :class: `Constant `
331
- nodes.
330
+ .. versionadded :: 3.14
331
+
332
+ Node representing a template string literal, comprising a series of
333
+ :class: `Interpolation ` and :class: `Constant ` nodes.
334
+ These nodes may be any order, and do not need to be interleaved.
332
335
333
336
.. doctest ::
334
337
335
- >>> print (ast.dump(ast.parse(' t"{name} finished {place: ordinal} "' , mode = ' eval' ), indent = 4 ))
338
+ >>> expr = ast.parse(' t"{name} finished {place: ordinal} "' , mode = ' eval' )
339
+ >>> print (ast.dump(expr, indent = 4 ))
336
340
Expression(
337
341
body=TemplateStr(
338
342
values=[
@@ -349,28 +353,28 @@ Literals
349
353
values=[
350
354
Constant(value='ordinal')]))]))
351
355
352
- .. versionadded :: 3.14
353
-
356
+ .. class :: Interpolation(value, str, conversion, format_spec=None)
354
357
355
- .. class :: Interpolation(value, str, conversion, format_spec)
358
+ .. versionadded :: 3.14
356
359
357
- Node representing a single interpolation field in a t- string.
360
+ Node representing a single interpolation field in a template string literal .
358
361
359
362
* ``value `` is any expression node (such as a literal, a variable, or a
360
363
function call).
364
+ This has the same meaning as ``FormattedValue.value ``.
361
365
* ``str `` is a constant containing the text of the interpolation expression.
362
366
* ``conversion `` is an integer:
363
367
364
368
* -1: no conversion
365
- * 115 : ``!s `` string conversion
366
- * 114: ``!r `` repr conversion
367
- * 97 : ``!a `` ascii conversion
369
+ * 97 (`` ord('a') ``) : ``!a `` :func: ` ASCII <ascii> ` conversion
370
+ * 114 (`` ord('r') ``) : ``!r `` :func: ` repr ` conversion
371
+ * 115 (`` ord('s') ``) : ``!s `` :func: ` string <str> ` conversion
368
372
373
+ This has the same meaning as ``FormattedValue.conversion ``.
369
374
* ``format_spec `` is a :class: `JoinedStr ` node representing the formatting
370
375
of the value, or ``None `` if no format was specified. Both
371
376
``conversion `` and ``format_spec `` can be set at the same time.
372
-
373
- .. versionadded :: 3.14
377
+ This has the same meaning as ``FormattedValue.format_spec ``.
374
378
375
379
376
380
.. class :: List(elts, ctx)
0 commit comments