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