summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_traceback.py
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhan@python.org>2021-07-25 22:01:44 (GMT)
committerGitHub <noreply@github.com>2021-07-25 22:01:44 (GMT)
commit3e235e0447e373d81f195f4292959c7be9c013dc (patch)
tree3fe06bef120b56ff47d75abd70b32db050b7c99b /Lib/test/test_traceback.py
parent96cf5a63d2dbadaebf236362b4c7c09c51fda55c (diff)
downloadcpython-3e235e0447e373d81f195f4292959c7be9c013dc.zip
cpython-3e235e0447e373d81f195f4292959c7be9c013dc.tar.gz
cpython-3e235e0447e373d81f195f4292959c7be9c013dc.tar.bz2
bpo-43950: support some multi-line expressions for PEP 657 (GH-27339)
This is basically something that I noticed up while fixing test runs for another issue. It is really common to have multiline calls, and when they fail the display is kind of weird since we omit the annotations. E.g; ``` $ ./python t.py Traceback (most recent call last): File "/home/isidentical/cpython/cpython/t.py", line 11, in <module> frame_1() ^^^^^^^^^ File "/home/isidentical/cpython/cpython/t.py", line 5, in frame_1 frame_2( File "/home/isidentical/cpython/cpython/t.py", line 2, in frame_2 return a / 0 / b / c ~~^~~ ZeroDivisionError: division by zero ``` This patch basically adds support for annotating the rest of the line, if the instruction covers multiple lines (start_line != end_line). Automerge-Triggered-By: GH:isidentical
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r--Lib/test/test_traceback.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 5fc5b59..5d48e9d 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -429,6 +429,30 @@ class TracebackErrorLocationCaretTests(unittest.TestCase):
' ^^^^^^^^^^\n'
f' File "{__file__}", line {lineno_f+1}, in f_with_multiline\n'
' raise ValueError(\n'
+ ' ^^^^^^^^^^^^^^^^^'
+ )
+ result_lines = self.get_exception(f_with_multiline)
+ self.assertEqual(result_lines, expected_f.splitlines())
+
+ def test_caret_multiline_expression_bin_op(self):
+ # Make sure no carets are printed for expressions spanning multiple
+ # lines.
+ def f_with_multiline():
+ return (
+ 1 /
+ 0 +
+ 2
+ )
+
+ lineno_f = f_with_multiline.__code__.co_firstlineno
+ expected_f = (
+ 'Traceback (most recent call last):\n'
+ f' File "{__file__}", line {self.callable_line}, in get_exception\n'
+ ' callable()\n'
+ ' ^^^^^^^^^^\n'
+ f' File "{__file__}", line {lineno_f+2}, in f_with_multiline\n'
+ ' 1 /\n'
+ ' ^^^'
)
result_lines = self.get_exception(f_with_multiline)
self.assertEqual(result_lines, expected_f.splitlines())