
Then how will modules that customizes traceback presentation, such as idlelib, be able to get the 4-tuple for a particular traceback entry?
From the exception, you can get the code object and from the code object the extra information using the Python API:
Example:
try: ... 1/0 ... except Exception as e: ... f = e
list(f.__traceback__.tb_frame.f_code.co_positions()) [(1, 4, 1, 8), (2, 2, 3, 4), (2, 2, 5, 6), (2, 2, 3, 6), (2, 2, 3, 6), (2, 4, 3, 8), (2, 4, 3, 8), (None, 2, 3, 6), (3, 4, 1, 8), (3, 3, 8, 17), (3, 4, 1, 8), (3, 4, 1, 8), (3, 4, 1, 8), (3, 4, 1, 8), (4, 4, 7, 8), (4, 4, 3, 4), (4, 4, 3, 8), (4, 4, 3, 8), (4, 4, 3, 8), (4, 4, 3, 8), (4, 4, 3, 8), (4, 4, 3, 8), (None, 4, 3, 8), (None, 4, 3, 8), (None, 4, 3, 8), (None, 4, 3, 8), (None, 4, 3, 8), (3, 4, 3, 8)]
Ah, co_positions is an access method, corresponding to the current (also undocumented) co_lines. There will be no direct access to the position-table as it will be kept private and subject to change. The obvious first question: why 28 items and what does the index mean? When I compile the above with 3.10.0b3, there are 29 bytecodes, so I am guessing your branch has 28 and that the first number in the tuple is the line number. But how would one know which '2' entry corresponds to the divide in '1/0'. And what do the rest of the tuple numbers mean? I don't see anything like the (2,2, 2,4) I expect for '1/0'. To be documented, as you say below.
This is equivalent (and more efficient) to have this information in the traceback itself (as it would have been duplicated and would require more changes).
Understood and agreed.
We would document this a bit better with some examples. And we will make sure to add docs about this for sure :)
-- Terry Jan Reedy