mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-106922: Fix error location for constructs with spaces and parentheses (#108959)
This commit is contained in:
parent
aa51182320
commit
6275c67ea6
4 changed files with 68 additions and 3 deletions
|
@ -596,6 +596,24 @@ class TracebackErrorLocationCaretTestBase:
|
|||
result_lines = self.get_exception(f_with_binary_operator)
|
||||
self.assertEqual(result_lines, expected_error.splitlines())
|
||||
|
||||
def test_caret_for_binary_operators_with_spaces_and_parenthesis(self):
|
||||
def f_with_binary_operator():
|
||||
a = 1
|
||||
b = ""
|
||||
return ( a ) + b
|
||||
|
||||
lineno_f = f_with_binary_operator.__code__.co_firstlineno
|
||||
expected_error = (
|
||||
'Traceback (most recent call last):\n'
|
||||
f' File "{__file__}", line {self.callable_line}, in get_exception\n'
|
||||
' callable()\n'
|
||||
f' File "{__file__}", line {lineno_f+3}, in f_with_binary_operator\n'
|
||||
' return ( a ) + b\n'
|
||||
' ~~~~~~~~~~^~~\n'
|
||||
)
|
||||
result_lines = self.get_exception(f_with_binary_operator)
|
||||
self.assertEqual(result_lines, expected_error.splitlines())
|
||||
|
||||
def test_caret_for_subscript(self):
|
||||
def f_with_subscript():
|
||||
some_dict = {'x': {'y': None}}
|
||||
|
@ -630,6 +648,24 @@ class TracebackErrorLocationCaretTestBase:
|
|||
result_lines = self.get_exception(f_with_subscript)
|
||||
self.assertEqual(result_lines, expected_error.splitlines())
|
||||
|
||||
def test_caret_for_subscript_with_spaces_and_parenthesis(self):
|
||||
def f_with_binary_operator():
|
||||
a = []
|
||||
b = c = 1
|
||||
return b [ a ] + c
|
||||
|
||||
lineno_f = f_with_binary_operator.__code__.co_firstlineno
|
||||
expected_error = (
|
||||
'Traceback (most recent call last):\n'
|
||||
f' File "{__file__}", line {self.callable_line}, in get_exception\n'
|
||||
' callable()\n'
|
||||
f' File "{__file__}", line {lineno_f+3}, in f_with_binary_operator\n'
|
||||
' return b [ a ] + c\n'
|
||||
' ~~~~~~^^^^^^^^^\n'
|
||||
)
|
||||
result_lines = self.get_exception(f_with_binary_operator)
|
||||
self.assertEqual(result_lines, expected_error.splitlines())
|
||||
|
||||
def test_traceback_specialization_with_syntax_error(self):
|
||||
bytecode = compile("1 / 0 / 1 / 2\n", TESTFN, "exec")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue