title: Python 3.7 bytecode MAKE_FUNCTION: How to interpret such disassembled function declaration?
body: <p>Here is my code:</p>
  
  <pre><code>x=100
  def foo(m, n=66):
      return m + n  
  
  b=200
  a=foo(x) + b
  print(a)
  </code></pre>
  
  <p>Here is the disassembled:</p>
  
  <pre><code>$ python3 -m dis test_func.py
    1           0 LOAD_CONST               0 (100)
                2 STORE_NAME               0 (x)
  
    2           4 LOAD_CONST               6 ((66,))
                6 LOAD_CONST               2 (&lt;code object foo at 0x7f2c7dba39c0, file "test_func.py", line 2&gt;)
                8 LOAD_CONST               3 ('foo')
               10 MAKE_FUNCTION            1
               12 STORE_NAME               1 (foo)
  
    5          14 LOAD_CONST               4 (200)
               16 STORE_NAME               2 (b)
  
    6          18 LOAD_NAME                1 (foo)
               20 LOAD_NAME                0 (x)
               22 CALL_FUNCTION            1
               24 LOAD_NAME                2 (b)
               26 BINARY_ADD
               28 STORE_NAME               3 (a)
  
    7          30 LOAD_NAME                4 (print)
               32 LOAD_NAME                3 (a)
               34 CALL_FUNCTION            1
               36 POP_TOP
               38 LOAD_CONST               5 (None)
               40 RETURN_VALUE
  </code></pre>
  
  <p>My question is around this part:</p>
  
  <pre><code>  2           4 LOAD_CONST               6 ((66,))
                6 LOAD_CONST               2 (&lt;code object foo at 0x7f2c7dba39c0, file "test_func.py", line 2&gt;)
                8 LOAD_CONST               3 ('foo')
               10 MAKE_FUNCTION            1
  </code></pre>
  
  <p>Here is the snippet from the <a href="https://docs.python.org/3/library/dis.html" rel="nofollow noreferrer">document</a> about MAKE_FUNCTION:</p>
  
  <pre><code>MAKE_FUNCTION(argc)
  Pushes a new function object on the stack. From bottom to top, the consumed stack must consist of values if the argument carries a specified flag value:
  
  0x01   a tuple of default values for positional-only and positional-or-keyword parameters in positional order
  0x02   a dictionary of keyword-only parameters’ default values
  0x04   an annotation dictionary
  0x08   a tuple containing cells for free variables, making a closure
  the code associated with the function (at TOS1)
  the qualified name of the function (at TOS)
  </code></pre>
  
  <p>I have a hard time interpreting the flags: I do not see any flag in the disassembly.</p>
  
  <p>So let's correlate the disassembly with the doc, when it runs to MAKE_FUNCTION, the stack depth is 3:</p>
  
  <pre><code>1. the top is "foo" which comes from instruction @8
  2. the next one is code object which comes from instruction @6
  3. the bottom one is 66 which comes from instruction @4
  </code></pre>
  
  <p>Now my question is, where in this bytecode is the "flag"? I mean 0x01, 0x02, 0x04 and/or 0x08 mentioned in the doc. Is that "6" in instruction @4? But 6 is 2 and 4 while here it is only positional parameters......</p>
  
  <p>Please help out.</p>
  
  <p>Thanks!</p>