[issue13026] Dis module - documentation of MAKE_FUNCTION

New submission from Arnaud Delobelle <arnodel@googlemail.com>: The description of the opcode MAKE_FUNCTION in the dis module document is out of date. It still describes the 2.X version of the opcode: """ MAKE_FUNCTION(argc) Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS. """ According to http://hg.python.org/cpython/file/default/Python/ceval.c#l2684: 2684 int posdefaults = oparg & 0xff; 2685 int kwdefaults = (oparg>>8) & 0xff; 2686 int num_annotations = (oparg >> 16) & 0x7fff; So the documentation should read something like """ MAKE_FUNCTION(argc) Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc & 0xFF positional default parameters, (argc >> 8) & 0xFF keyword only default parameters, and (argc >> 16) & 0x7FFF parameter annotations which are push below TOS in this order. For each keyword only default, the name of the parameter is pushed just below its default value. On top of all the annotations, a tuple is pushed listing the parameter names for these annotations. """ ---------- assignee: docs@python components: Documentation messages: 144393 nosy: arno, docs@python, terry.reedy priority: normal severity: normal status: open title: Dis module - documentation of MAKE_FUNCTION versions: Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: Minor edit: in 'which are push below TOS', /push/pushed/. I understand 'in this order' to mean that positional defaults are pushed first so that they end up on the bottom, whereas annotations are pushed last and end up just under the code object. Correct? (This order makes sense given the structure of function headers.) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Arnaud Delobelle <arnodel@googlemail.com> added the comment: Yes, you are correct. Reading this again, I don't think I should have used the word "pushed" as it sounds like the effect of the opcode is to push stuff onto the stack, whereas I was only trying to describe what is on the stack just before the opcode is executed. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: Right. This opcode is the end of a sequence of opcodes that sets up the stack in the way expected. Perhaps something like Pushes a new function object on the stack. From bottom to top, the consumed stack must have have argc & 0xFF positional default parameter objects, (argc >> 8) & 0xFF keyword only name, default parameter object pairs (with name and object in separate positions), (argc >> 16) & 0x7FFF parameter annotations, a tuple listing the parameter names for the annotations, and finally a code object as TOS. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Arnaud Delobelle <arnodel@googlemail.com> added the comment: This reads a lot better. Perhaps change (with name and object in separate positions) to something like (with name just below object on the stack) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: Agreed ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Sandro Tosi <sandro.tosi@gmail.com> added the comment: Hi Arnaud, would you like to provide a patch to update the MAKE_FUNCTION opcode description? That would speed up a bit the fix-up. Also, I don't have that clear what "For each keyword only default, ..." mean: are those the default values for keyword arguments? something else? Thanks in advance, Sandro ---------- nosy: +sandro.tosi stage: -> needs patch versions: +Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: "For each keyword only default" is not in my text, but if you are referring to "keyword only name, default parameter object pairs ", yes. Here is a revised suggested wording: MAKE_FUNCTION(argc) Pushes a new function object on the stack. From bottom to top, the consumed stack must have have (argc & 0xFF) default argument objects in positional order, ((argc >> 8) & 0xFF) (name, default argument) pairs, with name just below the object on the stack, for keyword-only parameters, ((argc >> 16) & 0x7FFF) parameter annotation objects, a tuple listing the parameter names for the annotations, and finally a code object as TOS. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________

Roundup Robot added the comment: New changeset b9ab48c491d5 by Georg Brandl in branch '3.3': Closes #13026: fix documentation of MAKE_FUNCTION for 3.x. http://hg.python.org/cpython/rev/b9ab48c491d5 ---------- nosy: +python-dev resolution: -> fixed stage: needs patch -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13026> _______________________________________
participants (4)
-
Arnaud Delobelle
-
Roundup Robot
-
Sandro Tosi
-
Terry J. Reedy