Skip to content

bpo-26110: Document CALL_METHOD_KW #26159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,18 @@ All of the following opcodes use their arguments.
.. versionadded:: 3.7


.. opcode:: CALL_METHOD_KW (argc)

Calls a method in a similar fashion as :opcode:`CALL_METHOD`, but also supports keyword arguments.
*argc* is the number of positional and keyword arguments.
This opcode is designed to be used with :opcode:`LOAD_METHOD`. TOS is a
tuple of keyword argument names. Argument values are below that.
Below them, the two items described in :opcode:`LOAD_METHOD` are on the
stack (either ``self`` and an unbound method object or ``NULL`` and an
arbitrary callable). All of them are popped from the stack and the return value is pushed.

.. versionadded:: 3.11

.. opcode:: MAKE_FUNCTION (flags)

Pushes a new function object on the stack. From bottom to top, the consumed
Expand Down
16 changes: 15 additions & 1 deletion Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Improved Modules
Optimizations
=============

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

* Method calls with keywords are now faster due to bytecode
changes which avoid creating bound method instances. Previously, this
optimization was applied only to method calls with purely positional
arguments.
(Contributed by Ken Jin and Mark Shannon in :issue:`26110`, based on ideas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the issue correct? In https://bugs.python.org/issue26110 I don't see any PR for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it didn't appear for some reason, there was some recent discussion about other issues having the same problem https://mail.python.org/archives/list/python-committers@python.org/thread/M2Z3WSJ4SGGH2GQ7D5NELAZSD3PECG7Q/ .

implemented in PyPy.)

CPython bytecode changes
========================

* Added a new :opcode:`CALL_METHOD_KW` opcode. Calls a method in a similar
fashion as :opcode:`CALL_METHOD`, but also supports keyword arguments. Works
in tandem with :opcode:`LOAD_METHOD`.


Build Changes
=============
Expand Down