improve the documentation of the LOAD_METHOD and CALL_METHOD (GH-18079)

This commit is contained in:
Carl Friedrich Bolz-Tereick 2020-01-21 01:41:17 +01:00 committed by Inada Naoki
parent 8d57a4182f
commit 8698b34b68
1 changed files with 10 additions and 8 deletions

View File

@ -1140,22 +1140,24 @@ All of the following opcodes use their arguments.
.. opcode:: LOAD_METHOD (namei) .. opcode:: LOAD_METHOD (namei)
Loads a method named ``co_names[namei]`` from TOS object. TOS is popped and Loads a method named ``co_names[namei]`` from the TOS object. TOS is popped.
method and TOS are pushed when interpreter can call unbound method directly. This bytecode distinguishes two cases: if TOS has a method with the correct
TOS will be used as the first argument (``self``) by :opcode:`CALL_METHOD`. name, the bytecode pushes the unbound method and TOS. TOS will be used as
Otherwise, ``NULL`` and method is pushed (method is bound method or the first argument (``self``) by :opcode:`CALL_METHOD` when calling the
something else). unbound method. Otherwise, ``NULL`` and the object return by the attribute
lookup are pushed.
.. versionadded:: 3.7 .. versionadded:: 3.7
.. opcode:: CALL_METHOD (argc) .. opcode:: CALL_METHOD (argc)
Calls a method. *argc* is number of positional arguments. Calls a method. *argc* is the number of positional arguments.
Keyword arguments are not supported. This opcode is designed to be used Keyword arguments are not supported. This opcode is designed to be used
with :opcode:`LOAD_METHOD`. Positional arguments are on top of the stack. with :opcode:`LOAD_METHOD`. Positional arguments are on top of the stack.
Below them, two items described in :opcode:`LOAD_METHOD` on the stack. Below them, the two items described in :opcode:`LOAD_METHOD` are on the
All of them are popped and return value is pushed. stack (either ``self`` and an unbound method object or ``NULL`` and an
arbitrary callable). All of them are popped and the return value is pushed.
.. versionadded:: 3.7 .. versionadded:: 3.7