From a758aa9631ee945f1f5555863c985fc6bad36071 Mon Sep 17 00:00:00 2001 From: tangyuan0821 Date: Mon, 18 Aug 2025 20:32:21 +0800 Subject: [PATCH] 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. --- Doc/library/dis.rst | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 7360f4aa804724..ba0ab6a93f6731 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -1259,13 +1259,18 @@ iterations of the loop. correct name, the bytecode pushes the unbound method and ``STACK[-1]``. ``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL` or :opcode:`CALL_KW` when calling the unbound method. - Otherwise, ``NULL`` and the object returned by - the attribute lookup are pushed. + Otherwise, the object returned by the attribute lookup and ``NULL`` are + pushed (in that order). .. versionchanged:: 3.12 - If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` is + If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` was pushed to the stack before the attribute or unbound method respectively. + .. versionchanged:: 3.13 + The push order changed to keep the callable at a fixed stack position for + :opcode:`CALL`: the attribute or unbound method is now pushed before the + ``NULL``/``self`` marker (previously the marker was pushed first). + .. opcode:: LOAD_SUPER_ATTR (namei) @@ -1283,7 +1288,8 @@ iterations of the loop. except that ``namei`` is shifted left by 2 bits instead of 1. The low bit of ``namei`` signals to attempt a method load, as with - :opcode:`LOAD_ATTR`, which results in pushing ``NULL`` and the loaded method. + :opcode:`LOAD_ATTR`, which results in pushing the loaded method and ``NULL`` + (in that order). When it is unset a single value is pushed to the stack. The second-low bit of ``namei``, if set, means that this was a two-argument @@ -1291,6 +1297,11 @@ iterations of the loop. .. versionadded:: 3.12 + .. versionchanged:: 3.13 + The push order for method loads changed to keep the callable at a fixed + stack position for :opcode:`CALL`: the loaded method is now pushed before + the ``NULL`` marker (previously the marker was pushed first). + .. opcode:: COMPARE_OP (opname) @@ -1422,6 +1433,11 @@ iterations of the loop. If the low bit of ``namei`` is set, then a ``NULL`` is pushed to the stack before the global variable. + .. versionchanged:: 3.13 + The push order changed to keep the callable at a fixed stack position for + :opcode:`CALL`: the global is now pushed before the ``NULL`` marker + (previously the marker was pushed first). + .. opcode:: LOAD_FAST (var_num) Pushes a reference to the local ``co_varnames[var_num]`` onto the stack.