[3.11] GH-94694: Fix column offsets for multi-line method lookups (GH-94721)

(cherry picked from commit 264b3ddfd5)
This commit is contained in:
Brandt Bucher 2022-07-09 22:12:45 -07:00 committed by GitHub
parent 7b5737a51a
commit e5c8ad3e15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 2 deletions

View file

@ -703,6 +703,57 @@ class TracebackErrorLocationCaretTests(unittest.TestCase):
)
self.assertEqual(result_lines, expected_error.splitlines())
def test_multiline_method_call_a(self):
def f():
(None
.method
)()
actual = self.get_exception(f)
expected = [
f"Traceback (most recent call last):",
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
f" callable()",
f" ^^^^^^^^^^",
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 2}, in f",
f" .method",
f" ^^^^^^",
]
self.assertEqual(actual, expected)
def test_multiline_method_call_b(self):
def f():
(None.
method
)()
actual = self.get_exception(f)
expected = [
f"Traceback (most recent call last):",
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
f" callable()",
f" ^^^^^^^^^^",
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 2}, in f",
f" method",
f" ^^^^^^",
]
self.assertEqual(actual, expected)
def test_multiline_method_call_c(self):
def f():
(None
. method
)()
actual = self.get_exception(f)
expected = [
f"Traceback (most recent call last):",
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
f" callable()",
f" ^^^^^^^^^^",
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 2}, in f",
f" . method",
f" ^^^^^^",
]
self.assertEqual(actual, expected)
@cpython_only
@requires_debug_ranges()
class CPythonTracebackErrorCaretTests(TracebackErrorLocationCaretTests):