Skip to content

gh-106922: Support multi-line error locations in traceback #109589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
8 changes: 7 additions & 1 deletion Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,17 @@ def raise_exc(exc):
self.assertIsInstance(exc, ValueError)
ve_frames = traceback.extract_tb(exc.__traceback__)
expected = \
[('test_exit_exception_traceback', 'with self.exit_stack() as stack:')] + \
[(
'test_exit_exception_traceback',
'with self.exit_stack() as stack:\n'
' stack.callback(raise_exc, ValueError)\n'
' 1/0'
)] + \
self.callback_error_internal_frames + \
[('_exit_wrapper', 'callback(*args, **kwds)'),
('raise_exc', 'raise exc')]

# breakpoint()
self.assertEqual(
[(f.name, f.line) for f in ve_frames], expected)

Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,9 @@ def test_unicode(): """
Traceback (most recent call last):
File ...
exec(compile(example.source, filename, "single",
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
compileflags, True), test.globs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<doctest foo-bär@baz[0]>", line 1, in <module>
raise Exception('clé')
Exception: clé
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2045,14 +2045,15 @@ def test_multiline_not_highlighted(self):
""",
[
' 1 < 2 and',
' 3 > 4',
'AssertionError',
],
),
]
for source, expected in cases:
with self.subTest(source):
result = self.write_source(source)
self.assertEqual(result[-2:], expected)
self.assertEqual(result[-len(expected):], expected)


class SyntaxErrorTests(unittest.TestCase):
Expand Down
Loading