[issue11822] Improve disassembly to show embedded code objects

Alexander Belopolsky report at bugs.python.org
Mon Apr 11 23:48:24 CEST 2011


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

On Mon, Apr 11, 2011 at 5:21 PM, Antoine Pitrou <report at bugs.python.org> wrote:
..
Raymond>> If you disassemble a function, you typically want to see all the code
Raymond>> [defined] in that function.

+1 (with clarification in [])

If the function calls a function defined elsewhere, I don't want to
see the called function disassembly when I disassemble the caller.  In
this case it is very easy to disassemble interesting functions with
separate dis() calls.  In the case like the following, however:

def f():
  def g(x):
      return x**2
dis(f)
2           0 LOAD_CONST               1 (<code object g at
0x10055ce88, file "x.py", line 2>)
              3 MAKE_FUNCTION            0
              6 STORE_FAST               0 (g)
...

when I see '<code object g at 0x10055ce88, ..>', I have to do
something unwieldy such as

  3           0 LOAD_FAST                0 (x)
              3 LOAD_CONST               1 (2)
              6 BINARY_POWER
              7 RETURN_VALUE

>
> That depends on the function. If you do event-driven programming (say,
> Twisted deferreds with addCallback()), you don't necessarily want to see
> the disassembly of the callbacks that are passed to the various
> framework functions. Also, if you do so recursively, it might become
> *very* unwieldy.

Can you provide some examples of this?  Nested functions are typically
short and even if they are long, the size disassembly would be
proportional to the line count of the function being disassembled,
which is expected.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11822>
_______________________________________


More information about the Python-bugs-list mailing list