Skip to content

Commit afa591d

Browse files
[2.7] bpo-33216: Clarify the documentation for CALL_FUNCTION_* (GH-8338) (GH-8783)
(cherry picked from commit 76aa2c0) Co-authored-by: larryhastings <[email protected]>
1 parent 57e70d3 commit afa591d

File tree

1 file changed

+53
-20
lines changed

1 file changed

+53
-20
lines changed

Doc/library/dis.rst

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ The :mod:`dis` module defines the following functions and constants:
107107

108108
.. data:: hasconst
109109

110-
Sequence of bytecodes that have a constant parameter.
110+
Sequence of bytecodes that access a constant.
111111

112112

113113
.. data:: hasfree
@@ -796,21 +796,25 @@ the more significant byte last.
796796

797797
.. opcode:: RAISE_VARARGS (argc)
798798

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

803803

804804
.. opcode:: CALL_FUNCTION (argc)
805805

806-
Calls a function. The low byte of *argc* indicates the number of positional
807-
parameters, the high byte the number of keyword parameters. On the stack, the
808-
opcode finds the keyword parameters first. For each keyword argument, the
809-
value is on top of the key. Below the keyword parameters, the positional
810-
parameters are on the stack, with the right-most parameter on top. Below the
811-
parameters, the function object to call is on the stack. Pops all function
812-
arguments, and the function itself off the stack, and pushes the return
813-
value.
806+
Calls a callable object. The low byte of *argc* indicates the number of
807+
positional arguments, the high byte the number of keyword arguments.
808+
The stack contains keyword arguments on top (if any), then the positional
809+
arguments below that (if any), then the callable object to call below that.
810+
Each keyword argument is represented with two values on the stack:
811+
the argument's name, and its value, with the argument's value above the
812+
name on the stack.
813+
The positional arguments are pushed in the order that they are passed in
814+
to the callable object, with the right-most positional argument on top.
815+
``CALL_FUNCTION`` pops all arguments and the callable object off the stack,
816+
calls the callable object with those arguments, and pushes the return value
817+
returned by the callable object.
814818

815819

816820
.. opcode:: MAKE_FUNCTION (argc)
@@ -847,24 +851,53 @@ the more significant byte last.
847851

848852
.. opcode:: CALL_FUNCTION_VAR (argc)
849853

850-
Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The
851-
top element on the stack contains the variable argument list, followed by
852-
keyword and positional arguments.
854+
Calls a callable object, similarly to :opcode:`CALL_FUNCTION`.
855+
*argc* represents the number of keyword and positional
856+
arguments, identically to :opcode:`CALL_FUNCTION`.
857+
The top of the stack contains an iterable object containing
858+
additional positional arguments.
859+
Below that are keyword arguments (if any), positional arguments (if any)
860+
and a callable object, identically to :opcode:`CALL_FUNCTION`.
861+
Before the callable object is called, the iterable object
862+
is "unpacked" and its contents are appended to the positional
863+
arguments passed in.
864+
The iterable object is ignored when computing
865+
the value of ``argc``.
853866

854867

855868
.. opcode:: CALL_FUNCTION_KW (argc)
856869

857-
Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The
858-
top element on the stack contains the keyword arguments dictionary, followed
859-
by explicit keyword and positional arguments.
870+
Calls a callable object, similarly to :opcode:`CALL_FUNCTION`.
871+
*argc* represents the number of keyword and positional
872+
arguments, identically to :opcode:`CALL_FUNCTION`.
873+
The top of the stack contains a mapping object containing additional keyword
874+
arguments.
875+
Below that are keyword arguments (if any), positional arguments (if any)
876+
and a callable object, identically to :opcode:`CALL_FUNCTION`.
877+
Before the callable is called, the mapping object at the top of the stack is
878+
"unpacked" and its contents are appended to the keyword arguments passed in.
879+
The mapping object at the top of the stack is ignored when computing
880+
the value of ``argc``.
860881

861882

862883
.. opcode:: CALL_FUNCTION_VAR_KW (argc)
863884

864-
Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The
865-
top element on the stack contains the keyword arguments dictionary, followed
866-
by the variable-arguments tuple, followed by explicit keyword and positional
867-
arguments.
885+
Calls a callable object, similarly to :opcode:`CALL_FUNCTION_VAR` and
886+
:opcode:`CALL_FUNCTION_KW`.
887+
*argc* represents the number of keyword and positional
888+
arguments, identically to :opcode:`CALL_FUNCTION`.
889+
The top of the stack contains a mapping object, as per
890+
:opcode:`CALL_FUNCTION_KW`.
891+
Below that is an iterable object, as per
892+
:opcode:`CALL_FUNCTION_VAR`.
893+
Below that are keyword arguments (if any), positional arguments (if any)
894+
and a callable object, identically to :opcode:`CALL_FUNCTION`.
895+
Before the callable is called, the mapping object and iterable object
896+
are each "unpacked" and their contents passed in as keyword and
897+
positional arguments respectively,
898+
identically to :opcode:`CALL_FUNCTION_VAR` and :opcode:`CALL_FUNCTION_KW`.
899+
The mapping object and iterable object are both ignored when computing
900+
the value of ``argc``.
868901

869902

870903
.. opcode:: HAVE_ARGUMENT ()

0 commit comments

Comments
 (0)