Skip to content

Commit 226af23

Browse files
authored
bpo-26213: Document _UNPACK bytecodes and BUILD_MAP changes (GH-440)
(cherry picked from commit 0705f66)
1 parent 03f7cb0 commit 226af23

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

Doc/library/dis.rst

+53-2
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,13 @@ All of the following opcodes use their arguments.
772772

773773
.. opcode:: BUILD_MAP (count)
774774

775-
Pushes a new dictionary object onto the stack. The dictionary is pre-sized
776-
to hold *count* entries.
775+
Pushes a new dictionary object onto the stack. Pops ``2 * count`` items
776+
so that the dictionary holds *count* entries:
777+
``{..., TOS3: TOS2, TOS1: TOS}``.
778+
779+
.. versionchanged:: 3.5
780+
The dictionary is created from stack items instead of creating an
781+
empty dictionary pre-sized to hold *count* items.
777782

778783

779784
.. opcode:: BUILD_CONST_KEY_MAP (count)
@@ -793,6 +798,52 @@ All of the following opcodes use their arguments.
793798
.. versionadded:: 3.6
794799

795800

801+
.. opcode:: BUILD_TUPLE_UNPACK (count)
802+
803+
Pops *count* iterables from the stack, joins them in a single tuple,
804+
and pushes the result. Implements iterable unpacking in tuple
805+
displays ``(*x, *y, *z)``.
806+
807+
.. versionadded:: 3.5
808+
809+
810+
.. opcode:: BUILD_LIST_UNPACK (count)
811+
812+
This is similar to :opcode:`BUILD_TUPLE_UNPACK`, but pushes a list
813+
instead of tuple. Implements iterable unpacking in list
814+
displays ``[*x, *y, *z]``.
815+
816+
.. versionadded:: 3.5
817+
818+
819+
.. opcode:: BUILD_SET_UNPACK (count)
820+
821+
This is similar to :opcode:`BUILD_TUPLE_UNPACK`, but pushes a set
822+
instead of tuple. Implements iterable unpacking in set
823+
displays ``{*x, *y, *z}``.
824+
825+
.. versionadded:: 3.5
826+
827+
828+
.. opcode:: BUILD_MAP_UNPACK (count)
829+
830+
Pops *count* mappings from the stack, merges them into a single dictionary,
831+
and pushes the result. Implements dictionary unpacking in dictionary
832+
displays ``{**x, **y, **z}``.
833+
834+
.. versionadded:: 3.5
835+
836+
837+
.. opcode:: BUILD_MAP_UNPACK_WITH_CALL (oparg)
838+
839+
This is similar to :opcode:`BUILD_MAP_UNPACK`,
840+
but is used for ``f(**x, **y, **z)`` call syntax. The lowest byte of
841+
*oparg* is the count of mappings, the relative position of the
842+
corresponding callable ``f`` is encoded in the second byte of *oparg*.
843+
844+
.. versionadded:: 3.5
845+
846+
796847
.. opcode:: LOAD_ATTR (namei)
797848

798849
Replaces TOS with ``getattr(TOS, co_names[namei])``.

0 commit comments

Comments
 (0)