]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43950: support long lines in traceback.py (GH-27336)
authorBatuhan Taskaya <batuhan@python.org>
Sat, 24 Jul 2021 17:50:39 +0000 (20:50 +0300)
committerGitHub <noreply@github.com>
Sat, 24 Jul 2021 17:50:39 +0000 (20:50 +0300)
Lib/test/test_traceback.py
Lib/traceback.py

index c87ce7245335a8a55961a4e56f18ebe17cefb361..5fc5b5926d5a67d063c4f6fba6f8b0008ca52eeb 100644 (file)
@@ -510,6 +510,28 @@ class TracebackErrorLocationCaretTests(unittest.TestCase):
         )
         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]
index ae5775d2f3bdae981e88b3d048ca3b3e3e800322..15bdb3c8c2e650af157c3d77877ba903279a6619 100644 (file)
@@ -462,7 +462,11 @@ class StackSummary(list):
             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)