Nick Coghlan added the comment:

It's not quite that simple - the instruction responsible for the exception also 
needs to be recorded, and Bytecode doesn't currently allow for that (look at 
the way the "lasti" arg to disassemble is used in disttb, and then how that 
gets passed to the "mark_as_current" flag in Instruction._disassemble by 
_disassemble_bytes).

So, on reflection, I think a TracebackBytecode class may be a better idea, 
exposing "bytecode" and "last_offset" attributes.

Rather than iteration just producing instructions, it would produce 
(instruction, is_current) 2-tuples, and display_code would call through to 
"self.bytecode.display_code(self.last_offset)" (there would be no show_info() 
or info() methods on TracebackBytecode).

Bytecode.display_code would gain a new "current_offset" parameter, which it 
would pass through to _disassemble_bytes as the "lasti" parameter.

Reviewing this also made me realise "line_offset" in dis.get_instructions is 
misnamed - see issue 19378.

----------
dependencies: +Rename "line_offset" parameter in dis.get_instructions to 
"first_line"

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17916>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to