10000 bpo-33216: Improve the documentation for CALL_FUNCTION_* (GH-8338) (G… · python/cpython@1e7193b · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e7193b

Browse files
bpo-33216: Improve the documentation for CALL_FUNCTION_* (GH-8338) (GH-8784)
(cherry picked from commit 5e99b56) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent fff869e commit 1e7193b

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

Doc/library/dis.rst

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,50 +1043,57 @@ All of the following opcodes use their arguments.
10431043

10441044
.. opcode:: RAISE_VARARGS (argc)
10451045

1046-
Raises an exception. *argc* indicates the number of parameters to the raise
1046+
Raises an exception. *argc* indicates the number of arguments to the raise
10471047
statement, ranging from 0 to 3. The handler will find the traceback as TOS2,
10481048
the parameter as TOS1, and the exception as TOS.
10491049

10501050

10511051
.. opcode:: CALL_FUNCTION (argc)
10521052

1053-
Calls a function. *argc* indicates the number of positional arguments.
1054-
The positional arguments are on the stack, with the right-most argument
1055-
on top. Below the arguments, the function object to call is on the stack.
1056-
Pops all function arguments, and the function itself off the stack, and
1057-
pushes the return value.
1053+
Calls a callable object with positional arguments.
1054+
*argc* indicates the number of positional arguments.
1055+
The top of the stack contains positional arguments, with the right-most
1056+
argument on top. Below the arguments is a callable object to call.
1057+
``CALL_FUNCTION`` pops all arguments and the callable object off the stack,
1058+
calls the callable object with those arguments, and pushes the return value
1059+
returned by the callable object.
10581060

10591061
.. versionchanged:: 3.6
10601062
This opcode is used only for calls with positional arguments.
10611063

10621064

10631065
.. opcode:: CALL_FUNCTION_KW (argc)
10641066

1065-
Calls a function. *argc* indicates the number of arguments (positional
1066-
and keyword). The top element on the stack contains a tuple of keyword
1067-
argument names. Below the tuple, keyword arguments are on the stack, in
1068-
the order corresponding to the tuple. Below the keyword arguments, the
1069-
positional arguments are on the stack, with the right-most parameter on
1070-
top. Below the arguments, the function object to call is on the stack.
1071-
Pops all function arguments, and the function itself off the stack, and
1072-
pushes the return value.
1067+
Calls a callable object with positional (if any) and keyword arguments.
1068+
*argc* indicates the total number of positional and keyword arguments.
1069+
The top element on the stack contains a tuple of keyword argument names.
1070+
Below that are keyword arguments in the order corresponding to the tuple.
1071+
Below that are positional arguments, with the right-most parameter on
1072+
top. Below the arguments is a callable object to call.
1073+
``CALL_FUNCTION_KW`` pops all arguments and the callable object off the stack,
1074+
calls the callable object with those arguments, and pushes the return value
1075+
returned by the callable object.
10731076

10741077
.. versionchanged:: 3.6
10751078
Keyword arguments are packed in a tuple instead of a dictionary,
1076-
*argc* indicates the total number of arguments
1079+
*argc* indicates the total number of arguments.
10771080

10781081

10791082
.. opcode:: CALL_FUNCTION_EX (flags)
10801083

1081-
Calls a function. The lowest bit of *flags* indicates whether the
1082-
var-keyword argument is placed at the top of the stack. Below the
1083-
var-keyword argument, the var-positional argument is on the stack.
1084-
Below the arguments, the function object to call is placed.
1085-
Pops all function arguments, and the function itself off the stack, and
1086-
pushes the return value. Note that this opcode pops at most three items
1087-
from the stack. Var-positional and var-keyword arguments are packed
1088-
by :opcode:`BUILD_TUPLE_UNPACK_WITH_CALL` and
1089-
:opcode:`BUILD_MAP_UNPACK_WITH_CALL`.
1084+
Calls a callable object with variable set of positional and keyword
1085+
arguments. If the lowest bit of *flags* is set, the top of the stack
1086+
contains a mapping object containing additional keyword arguments.
1087+
Below that is an iterable object containing positional arguments and
1088+
a callable object to call. :opcode:`BUILD_MAP_UNPACK_WITH_CALL` and
1089+
:opcode:`BUILD_TUPLE_UNPACK_WITH_CALL` can be used for merging multiple
1090+
mapping objects and iterables containing arguments.
1091+
Before the callable is called, the mapping object and iterable object
1092+
are each "unpacked" and their contents passed in as keyword and
1093+
positional arguments respectively.
1094+
``CALL_FUNCTION_EX`` pops all arguments and the callable object off the stack,
1095+
calls the callable object with those arguments, and pushes the return value
1096+
returned by the callable object.
10901097

10911098
.. versionadded:: 3.6
10921099

@@ -1096,7 +1103,8 @@ All of the following opcodes use their arguments.
10961103
Pushes a new function object on the stack. From bottom to top, the consumed
10971104
stack must consist of values if the argument carries a specified flag value
10981105

1099-
* ``0x01`` a tuple of default argument objects in positional order
1106+
* ``0x01`` a tuple of default values for positional-only and
1107+
positional-or-keyword parameters in positional order
11001108
* ``0x02`` a dictionary of keyword-only parameters' default values
11011109
* ``0x04`` an annotation dictionary
11021110
* ``0x08`` a tuple containing cells for free variables, making a closure
@@ -1179,7 +1187,7 @@ instructions:
11791187

11801188
.. data:: hasconst
11811189

1182-
Sequence of bytecodes that have a constant parameter.
1190+
Sequence of bytecodes that access a constant.
11831191

11841192

11851193
.. data:: hasfree

0 commit comments

Comments
 (0)
0