You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invalid caret position when reconstructing traceback #76
Thanks for maintaining this library, it's been very useful.
I'm opening this issue to discuss an improvement that could create a better experience for developers when they are shown a stack trace for an exception that was reconstructed with tblib.Traceback.form_string(s).as_traceback().
In most cases, Python is able to show a caret below the expression that triggered the exception (e.g., as a sequence of ^).
The Python traceback package creates a FrameSummary containing colno and end_colno to track the position of the caret.
However, the dynamic traceback reconstruction that is done by tblib via compilation of code snippets results in a caret that is always ``:
The length corresponds to the length of the __traceback_maker type.
The column offset is somehow always interpreted as zero. That I haven't figured out why yet, I would expect it to be 6 since the full line triggering the exception is raise __traceback_maker.
There may be a relationship to #75 as well, since it is my understanding that the column offsets are derived from the instruction position in Python 3.11+.
def_walk_tb_with_full_positions(tb):
# Internal version of walk_tb that yields full code positions including# end line and column information.whiletbisnotNone:
positions=_get_code_position(tb.tb_frame.f_code, tb.tb_lasti)
# Yield tb_lineno when co_positions does not have a line number to# maintain behavior with walk_tb.ifpositions[0] isNone:
yieldtb.tb_frame, (tb.tb_lineno, ) +positions[1:]
else:
yieldtb.tb_frame, positionstb=tb.tb_nextdef_get_code_position(code, instruction_index):
ifinstruction_index<0:
return (None, None, None, None)
positions_gen=code.co_positions()
returnnext(itertools.islice(positions_gen, instruction_index//2, None))
Running into the same situation, I wonder if it's easier to modify the colnoend_colno on the frame object directly using tricks similar to tb_set_next.
Activity
hotpxl commentedon Oct 27, 2025
Running into the same situation, I wonder if it's easier to modify the
colnoend_colnoon the frame object directly using tricks similar totb_set_next.Preserve caret positions in Python 3.11+ tracebacks
Preserve caret positions in Python 3.11+ tracebacks
pablogsal commentedon Jan 25, 2026
Opened #91
Preserve caret positions in Python 3.11+ tracebacks