Skip to content

Commit

Permalink
undo unnecessary merge
Browse files Browse the repository at this point in the history
  • Loading branch information
blhsing committed Nov 20, 2024
1 parent 99a863a commit c720a3f
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,32 +400,18 @@ def walk_tb(tb):
tb = tb.tb_next


def _get_tb_position(tb):
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.
if positions[0] is None:
return tb.tb_frame, (tb.tb_lineno, ) + positions[1:]
return tb.tb_frame, positions


def _walk_tb_with_full_positions(tb, _seen=None):
def _walk_tb_with_full_positions(tb):
# Internal version of walk_tb that yields full code positions including
# end line and column information.
handler_tb = None
while tb is not None:
yield _get_tb_position(tb)
if tb.tb_lineno != tb.tb_frame.f_lineno and _seen:
for exc in reversed(_seen.values()):
if (handler_tb := exc.__traceback__) is not tb:
while handler_tb.tb_frame != tb.tb_frame:
if not (handler_tb := handler_tb.tb_next):
break
else:
break
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.
if positions[0] is None:
yield tb.tb_frame, (tb.tb_lineno, ) + positions[1:]
else:
yield tb.tb_frame, positions
tb = tb.tb_next
if handler_tb:
yield _get_tb_position(handler_tb)


def _get_code_position(code, instruction_index):
Expand Down Expand Up @@ -1063,14 +1049,14 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
# Handle loops in __cause__ or __context__.
is_recursive_call = _seen is not None
if _seen is None:
_seen = {}
_seen[id(exc_value)] = exc_value
_seen = set()
_seen.add(id(exc_value))

self.max_group_width = max_group_width
self.max_group_depth = max_group_depth

self.stack = StackSummary._extract_from_extended_frame_gen(
_walk_tb_with_full_positions(exc_traceback, _seen),
_walk_tb_with_full_positions(exc_traceback),
limit=limit, lookup_lines=lookup_lines,
capture_locals=capture_locals, cause=exc_value.__cause__,
context=exc_value.__context__)
Expand Down

0 comments on commit c720a3f

Please sign in to comment.