[issue11822] Improve disassembly to show embedded code objects

Nick Coghlan report at bugs.python.org
Sat Apr 15 11:50:09 EDT 2017


Nick Coghlan added the comment:

+1 for listing the nested code objects after the original one.

In reviewing Serhiy's patch, the core technical implementation looks OK to me, but I think we may want to go with a "depth" argument rather than a simple "recursive" flag.

My rationale for that relates to directly disassembling module and class source code:

- dis(module_source, depth=1) # Module, class bodies, function bodies
- dis(class_source, depth=1) # Class and method bodies

(with the default depth being 0, to disable recursive descent entirely)

Only if you set a higher depth than 1 would you start seeing things like closures, comprehension bodies, and nested classes.

With a simple all-or-nothing flag, I think module level recursive disassembly would be too noisy to be useful.

The bounded depth approach would also avoid a problem with invalid bytecode manipulations that manage to create a loop between two bytecode objects. While the *compiler* won't do that, there's no guarantee that the disassembler is being fed valid bytecode, so we should avoid exposing ourselves to any infinite loops in the display code.

----------

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


More information about the Python-bugs-list mailing list