Skip to content

Commit 38a7f78

Browse files
GH-93429: Document LOAD_METHOD removal (GH-93803)
1 parent a338e10 commit 38a7f78

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

Doc/library/dis.rst

+14-13
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,20 @@ iterations of the loop.
887887

888888
.. opcode:: LOAD_ATTR (namei)
889889

890-
Replaces TOS with ``getattr(TOS, co_names[namei])``.
890+
If the low bit of ``namei`` is not set, this replaces TOS with
891+
``getattr(TOS, co_names[namei>>1])``.
892+
893+
If the low bit of ``namei`` is set, this will attempt to load a method named
894+
``co_names[namei>>1]`` from the TOS object. TOS is popped.
895+
This bytecode distinguishes two cases: if TOS has a method with the correct
896+
name, the bytecode pushes the unbound method and TOS. TOS will be used as
897+
the first argument (``self``) by :opcode:`CALL` when calling the
898+
unbound method. Otherwise, ``NULL`` and the object return by the attribute
899+
lookup are pushed.
900+
901+
.. versionchanged:: 3.11
902+
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` is
903+
pushed to the stack before the attribute or unbound method respectively.
891904

892905

893906
.. opcode:: COMPARE_OP (opname)
@@ -1189,18 +1202,6 @@ iterations of the loop.
11891202
.. versionadded:: 3.6
11901203

11911204

1192-
.. opcode:: LOAD_METHOD (namei)
1193-
1194-
Loads a method named ``co_names[namei]`` from the TOS object. TOS is popped.
1195-
This bytecode distinguishes two cases: if TOS has a method with the correct
1196-
name, the bytecode pushes the unbound method and TOS. TOS will be used as
1197-
the first argument (``self``) by :opcode:`CALL` when calling the
1198-
unbound method. Otherwise, ``NULL`` and the object return by the attribute
1199-
lookup are pushed.
1200-
1201-
.. versionadded:: 3.7
1202-
1203-
12041205
.. opcode:: PUSH_NULL
12051206

12061207
Pushes a ``NULL`` to the stack.

Doc/whatsnew/3.12.rst

+9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ Optimizations
106106
(Contributed by Inada Naoki in :gh:`92536`.)
107107

108108

109+
CPython bytecode changes
110+
========================
111+
112+
* Removed the :opcode:`LOAD_METHOD` instruction. It has been merged into
113+
:opcode:`LOAD_ATTR`. :opcode:`LOAD_ATTR` will now behave like the old
114+
:opcode:`LOAD_METHOD` instruction if the low bit of its oparg is set.
115+
(Contributed by Ken Jin in :gh:`93429`.)
116+
117+
109118
Deprecated
110119
==========
111120

0 commit comments

Comments
 (0)