Skip to content

Commit 5c66195

Browse files
bpo-26110: Document CALL_METHOD_KW (GH-26159)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
1 parent f13a6a2 commit 5c66195

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Doc/library/dis.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,18 @@ All of the following opcodes use their arguments.
11761176
.. versionadded:: 3.7
11771177

11781178

1179+
.. opcode:: CALL_METHOD_KW (argc)
1180+
1181+
Calls a method in a similar fashion as :opcode:`CALL_METHOD`, but also supports keyword arguments.
1182+
*argc* is the number of positional and keyword arguments.
1183+
This opcode is designed to be used with :opcode:`LOAD_METHOD`. TOS is a
1184+
tuple of keyword argument names. Argument values are below that.
1185+
Below them, the two items described in :opcode:`LOAD_METHOD` are on the
1186+
stack (either ``self`` and an unbound method object or ``NULL`` and an
1187+
arbitrary callable). All of them are popped from the stack and the return value is pushed.
1188+
1189+
.. versionadded:: 3.11
1190+
11791191
.. opcode:: MAKE_FUNCTION (flags)
11801192

11811193
Pushes a new function object on the stack. From bottom to top, the consumed

Doc/whatsnew/3.11.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Improved Modules
9090
Optimizations
9191
=============
9292

93-
* Compiler optimizes now simple C-style formatting with literal format
93+
* Compiler now optimizes simple C-style formatting with literal format
9494
containing only format codes ``%s``, ``%r`` and ``%a`` and makes it as
9595
fast as corresponding f-string expression.
9696
(Contributed by Serhiy Storchaka in :issue:`28307`.)
@@ -99,6 +99,20 @@ Optimizations
9999
almost eliminated when no exception is raised.
100100
(Contributed by Mark Shannon in :issue:`40222`.)
101101

102+
* Method calls with keywords are now faster due to bytecode
103+
changes which avoid creating bound method instances. Previously, this
104+
optimization was applied only to method calls with purely positional
105+
arguments.
106+
(Contributed by Ken Jin and Mark Shannon in :issue:`26110`, based on ideas
107+
implemented in PyPy.)
108+
109+
CPython bytecode changes
110+
========================
111+
112+
* Added a new :opcode:`CALL_METHOD_KW` opcode. Calls a method in a similar
113+
fashion as :opcode:`CALL_METHOD`, but also supports keyword arguments. Works
114+
in tandem with :opcode:`LOAD_METHOD`.
115+
102116

103117
Build Changes
104118
=============

0 commit comments

Comments
 (0)