Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,17 @@ def format_frame_summary(self, frame_summary, colorize=False):
f' File "{__file__}", line {lno}, in f\n 1/0\n'
)

def test_traceback_empty_ast(self):
# see gh-122145
fs = traceback.FrameSummary("?", 1, "s", lookup_line=False,
locals=None, end_lineno=1, colno=0,
end_colno=10, line="#123456789")
self.assertListEqual(
traceback.StackSummary().format_frame_summary(fs).splitlines(),
[' File "?", line 1, in s', ' #123456789']
)


class Unrepresentable:
def __repr__(self) -> str:
raise Exception("Unrepresentable")
Expand Down
2 changes: 2 additions & 0 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ def _should_show_carets(self, start_offset, end_offset, all_lines, anchors):
with suppress(SyntaxError, ImportError):
import ast
tree = ast.parse('\n'.join(all_lines))
if not tree.body:
return False
statement = tree.body[0]
value = None
def _spawns_full_line(value):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an issue when reporting tracebacks containing only Python comments.
Patch by Bénédikt Tran.