[issue11822] Improve disassembly to show embedded code objects

Nick Coghlan report at bugs.python.org
Sat Apr 15 13:02:03 EDT 2017


Nick Coghlan added the comment:

The problem I see is that we have conflicting requirements for the default behaviour:

- if we modify dis() instead of adding a new function, then the default behaviour needs to be non-recursive for backwards compatibility reasons
- if we allow the depth to be configurable, then we'd like the default behaviour to be to show everything

One potential resolution to that would be to define this as a new function, `distree`, rather than modifying `dis` and `disassemble` to natively support recursion. Then the new function could accept a `depth` argument (addressing my concerns), but have `depth=None` as the default (addressing your concerns).

If we wanted to allow even more control than that, then I think os.walk provides a useful precedent, where we'd add a new `dis.walk` helper that just looked at `co_consts` to find nested code objects without doing any of the other disassembly work.

The dis.walk() helper would produce an iterable of (depth, code, nested) 3-tuples, where:

- the first item is the current depth in the compile tree
- the second is the code object itself
- the third is a list of nested code objects

Similar to os.walk(), editing the list of nested objects in place would let you control whether or not any further recursion took place.

----------

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


More information about the Python-bugs-list mailing list