Skip to content

Commit a758aa9

Browse files
committed
Subject: Doc: Note 3.13 stack order change for LOAD_GLOBAL/LOAD_ATTR/LOAD_SUPER_ATTR (gh-114212)
Body: In Python 3.13, to keep the callable at a fixed stack position for CALL/CALL_KW, the push order changed: the attribute/global/method is now pushed before the NULL/self marker.
1 parent 92be979 commit a758aa9

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Doc/library/dis.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,13 +1259,18 @@ iterations of the loop.
12591259
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
12601260
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
12611261
or :opcode:`CALL_KW` when calling the unbound method.
1262-
Otherwise, ``NULL`` and the object returned by
1263-
the attribute lookup are pushed.
1262+
Otherwise, the object returned by the attribute lookup and ``NULL`` are
1263+
pushed (in that order).
12641264

12651265
.. versionchanged:: 3.12
1266-
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` is
1266+
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` was
12671267
pushed to the stack before the attribute or unbound method respectively.
12681268

1269+
.. versionchanged:: 3.13
1270+
The push order changed to keep the callable at a fixed stack position for
1271+
:opcode:`CALL`: the attribute or unbound method is now pushed before the
1272+
``NULL``/``self`` marker (previously the marker was pushed first).
1273+
12691274

12701275
.. opcode:: LOAD_SUPER_ATTR (namei)
12711276

@@ -1283,14 +1288,20 @@ iterations of the loop.
12831288
except that ``namei`` is shifted left by 2 bits instead of 1.
12841289

12851290
The low bit of ``namei`` signals to attempt a method load, as with
1286-
:opcode:`LOAD_ATTR`, which results in pushing ``NULL`` and the loaded method.
1291+
:opcode:`LOAD_ATTR`, which results in pushing the loaded method and ``NULL``
1292+
(in that order).
12871293
When it is unset a single value is pushed to the stack.
12881294

12891295
The second-low bit of ``namei``, if set, means that this was a two-argument
12901296
call to :func:`super` (unset means zero-argument).
12911297

12921298
.. versionadded:: 3.12
12931299

1300+
.. versionchanged:: 3.13
1301+
The push order for method loads changed to keep the callable at a fixed
1302+
stack position for :opcode:`CALL`: the loaded method is now pushed before
1303+
the ``NULL`` marker (previously the marker was pushed first).
1304+
12941305

12951306
.. opcode:: COMPARE_OP (opname)
12961307

@@ -1422,6 +1433,11 @@ iterations of the loop.
14221433
If the low bit of ``namei`` is set, then a ``NULL`` is pushed to the
14231434
stack before the global variable.
14241435

1436+
.. versionchanged:: 3.13
1437+
The push order changed to keep the callable at a fixed stack position for
1438+
:opcode:`CALL`: the global is now pushed before the ``NULL`` marker
1439+
(previously the marker was pushed first).
1440+
14251441
.. opcode:: LOAD_FAST (var_num)
14261442

14271443
Pushes a reference to the local ``co_varnames[var_num]`` onto the stack.

0 commit comments

Comments
 (0)