cpython icon indicating copy to clipboard operation
cpython copied to clipboard

The documentation of MAKE_FUNCTION in Python 3.11 does not reflect the actual usage

Open fabioz opened this issue 3 years ago • 1 comments

Documentation

The documentation for 3.11 (https://docs.python.org/3.11/library/dis.html#opcode-MAKE_FUNCTION) related to MAKE_FUNCTION seems to be the same for Python 3.10, which would expect 2 elements to be removed from the stack, yet, it seems that only 1 element is removed from the stack (it appears that the qualifier is no longer there).

i.e.: Given:

import dis

def func():
    def check():
        pass

dis.dis(func)

The output I have in 3.11 is:

  4           0 RESUME                   0

  5           2 LOAD_CONST               1 (<code object check at 0x000001F555E3EAD0, file "W:\pydev.debugger\check\snippet6.py", line 5>)
              4 MAKE_FUNCTION            0
              6 STORE_FAST               0 (check)
              8 LOAD_CONST               0 (None)
             10 RETURN_VALUE

Disassembly of <code object check at 0x000001F555E3EAD0, file "W:\pydev.debugger\check\snippet6.py", line 5>:
  5           0 RESUME                   0

  6           2 LOAD_CONST               0 (None)
              4 RETURN_VALUE

and in 3.10 it is:

  5           0 LOAD_CONST               1 (<code object check at 0x000001F384D5D370, file "W:\pydev.debugger\check\snippet6.py", line 5>)
              2 LOAD_CONST               2 ('func.<locals>.check')
              4 MAKE_FUNCTION            0
              6 STORE_FAST               0 (check)
              8 LOAD_CONST               0 (None)
             10 RETURN_VALUE

Disassembly of <code object check at 0x000001F384D5D370, file "W:\pydev.debugger\check\snippet6.py", line 5>:
  6           0 LOAD_CONST               0 (None)
              2 RETURN_VALUE

The __qualname__ still seems to be set in the function (but that's probably happening through some other way now...).

fabioz avatar May 26 '22 19:05 fabioz

https://github.com/python/cpython/pull/93189 appears to be a fix for this doc issue

Christopher-Chianelli avatar Nov 07 '22 20:11 Christopher-Chianelli