mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
[3.11] gh-93883: elide traceback indicators when possible (GH-93994) (GH-94740)
Elide traceback column indicators when the entire line of the frame is implicated. This reduces traceback length and draws more attention to the remaining (very relevant) indicators. Example: ``` Traceback (most recent call last): File "query.py", line 99, in <module> bar() File "query.py", line 66, in bar foo() File "query.py", line 37, in foo magic_arithmetic('foo') File "query.py", line 18, in magic_arithmetic return add_counts(x) / 25 ^^^^^^^^^^^^^ File "query.py", line 24, in add_counts return 25 + query_user(user1) + query_user(user2) ^^^^^^^^^^^^^^^^^ File "query.py", line 32, in query_user return 1 + query_count(db, response['a']['b']['c']['user'], retry=True) ~~~~~~~~~~~~~~~~~~^^^^^ TypeError: 'NoneType' object is not subscriptable ``` Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
parent
f3212b1ec7
commit
45896f2a02
9 changed files with 111 additions and 139 deletions
|
@ -465,7 +465,8 @@ class StackSummary(list):
|
|||
row.append(' File "{}", line {}, in {}\n'.format(
|
||||
frame_summary.filename, frame_summary.lineno, frame_summary.name))
|
||||
if frame_summary.line:
|
||||
row.append(' {}\n'.format(frame_summary.line.strip()))
|
||||
stripped_line = frame_summary.line.strip()
|
||||
row.append(' {}\n'.format(stripped_line))
|
||||
|
||||
orig_line_len = len(frame_summary._original_line)
|
||||
frame_line_len = len(frame_summary.line.lstrip())
|
||||
|
@ -486,19 +487,22 @@ class StackSummary(list):
|
|||
frame_summary._original_line[colno - 1:end_colno - 1]
|
||||
)
|
||||
else:
|
||||
end_colno = stripped_characters + len(frame_summary.line.strip())
|
||||
end_colno = stripped_characters + len(stripped_line)
|
||||
|
||||
row.append(' ')
|
||||
row.append(' ' * (colno - stripped_characters))
|
||||
# show indicators if primary char doesn't span the frame line
|
||||
if end_colno - colno < len(stripped_line) or (
|
||||
anchors and anchors.right_start_offset - anchors.left_end_offset > 0):
|
||||
row.append(' ')
|
||||
row.append(' ' * (colno - stripped_characters))
|
||||
|
||||
if anchors:
|
||||
row.append(anchors.primary_char * (anchors.left_end_offset))
|
||||
row.append(anchors.secondary_char * (anchors.right_start_offset - anchors.left_end_offset))
|
||||
row.append(anchors.primary_char * (end_colno - colno - anchors.right_start_offset))
|
||||
else:
|
||||
row.append('^' * (end_colno - colno))
|
||||
if anchors:
|
||||
row.append(anchors.primary_char * (anchors.left_end_offset))
|
||||
row.append(anchors.secondary_char * (anchors.right_start_offset - anchors.left_end_offset))
|
||||
row.append(anchors.primary_char * (end_colno - colno - anchors.right_start_offset))
|
||||
else:
|
||||
row.append('^' * (end_colno - colno))
|
||||
|
||||
row.append('\n')
|
||||
row.append('\n')
|
||||
|
||||
if frame_summary.locals:
|
||||
for name, value in sorted(frame_summary.locals.items()):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue