FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-43950: support long lines in traceback.py by isidentical · Pull Request #27336 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 22 additions & 0 deletions Lib/test/test_traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,28 @@ def test_traceback_specialization_with_syntax_error(self):
)
self.assertEqual(result_lines, expected_error.splitlines())

def test_traceback_very_long_line(self):
source = "a" * 256
bytecode = compile(source, TESTFN, "exec")

with open(TESTFN, "w") as file:
file.write(source)
self.addCleanup(unlink, TESTFN)

func = partial(exec, bytecode)
result_lines = self.get_exception(func)

lineno_f = bytecode.co_firstlineno
expected_error = (
'Traceback (most recent call last):\n'
f' File "{__file__}", line {self.callable_line}, in get_exception\n'
' callable()\n'
' ^^^^^^^^^^\n'
f' File "{TESTFN}", line {lineno_f}, in <module>\n'
f' {source}\n'
)
self.assertEqual(result_lines, expected_error.splitlines())

def assertSpecialized(self, func, expected_specialization):
result_lines = self.get_exception(func)
specialization_line = result_lines[-1]
Expand Down
6 changes: 5 additions & 1 deletion Lib/traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ def format_frame(self, frame):
row.append(' {}\n'.format(frame.line.strip()))

stripped_characters = len(frame._original_line) - len(frame.line.lstrip())
if frame.end_lineno == frame.lineno and frame.end_colno != 0:
if (
frame.end_lineno == frame.lineno
and frame.colno is not None
and frame.end_colno is not None
):
colno = _byte_offset_to_character_offset(frame._original_line, frame.colno)
end_colno = _byte_offset_to_character_offset(frame._original_line, frame.end_colno)

Expand Down

Back | FazBrowse Home | New Git URL