Skip to content

Commit 8484b81

Browse files
committed
First pass at documenting BUILD_TEMPLATE and BUILD_INTERPOLATION
1 parent f2e5ca4 commit 8484b81

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Doc/library/dis.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,45 @@ iterations of the loop.
11201120
.. versionadded:: 3.12
11211121

11221122

1123+
.. opcode:: BUILD_TEMPLATE
1124+
1125+
Constructs a new :class:`~string.templatelib.Template` from a tuple
1126+
of strings and a tuple of interpolations and pushes the resulting instance
1127+
onto the stack::
1128+
1129+
interpolations = STACK.pop()
1130+
strings = STACK.pop()
1131+
STACK.append(_build_template(strings, interpolations))
1132+
1133+
.. versionadded:: 3.14
1134+
1135+
1136+
.. opcode:: BUILD_INTERPOLATION (format)
1137+
1138+
Constructs a new :class:`~string.templatelib.Interpolation` from an
1139+
expression and its source text and pushes the resulting instance onto the
1140+
stack.
1141+
1142+
If the low bit of ``format`` is set, it indicates that the interpolation
1143+
contains a format specification.
1144+
1145+
If ``format >> 2`` is non-zero, it indicates that the interpolation
1146+
contains a conversion. The value of ``format >> 2`` is the conversion type
1147+
(e.g. ``0`` for no conversion, ``1`` for ``!s``, ``2`` for ``!r``, and
1148+
``3`` for ``!a``)::
1149+
1150+
if format & 1:
1151+
format_spec = STACK.pop()
1152+
else:
1153+
format_spec = None
1154+
conversion = format >> 2
1155+
expression = STACK.pop()
1156+
value = STACK.pop()
1157+
STACK.append(_build_interpolation(value, expression, conversion, format_spec))
1158+
1159+
.. versionadded:: 3.14
1160+
1161+
11231162
.. opcode:: BUILD_TUPLE (count)
11241163

11251164
Creates a tuple consuming *count* items from the stack, and pushes the

0 commit comments

Comments
 (0)