@@ -596,6 +596,24 @@ def f_with_binary_operator():
596596 result_lines = self .get_exception (f_with_binary_operator )
597597 self .assertEqual (result_lines , expected_error .splitlines ())
598598
599+ def test_caret_for_binary_operators_with_spaces_and_parenthesis (self ):
600+ def f_with_binary_operator ():
601+ a = 1
602+ b = ""
603+ return ( a ) + b
604+
605+ lineno_f = f_with_binary_operator .__code__ .co_firstlineno
606+ expected_error = (
607+ 'Traceback (most recent call last):\n '
608+ f' File "{ __file__ } ", line { self .callable_line } , in get_exception\n '
609+ ' callable()\n '
610+ f' File "{ __file__ } ", line { lineno_f + 3 } , in f_with_binary_operator\n '
611+ ' return ( a ) + b\n '
612+ ' ~~~~~~~~~~^~~\n '
613+ )
614+ result_lines = self .get_exception (f_with_binary_operator )
615+ self .assertEqual (result_lines , expected_error .splitlines ())
616+
599617 def test_caret_for_subscript (self ):
600618 def f_with_subscript ():
601619 some_dict = {'x' : {'y' : None }}
@@ -630,6 +648,24 @@ def f_with_subscript():
630648 result_lines = self .get_exception (f_with_subscript )
631649 self .assertEqual (result_lines , expected_error .splitlines ())
632650
651+ def test_caret_for_subscript_with_spaces_and_parenthesis (self ):
652+ def f_with_binary_operator ():
653+ a = []
654+ b = c = 1
655+ return b [ a ] + c
656+
657+ lineno_f = f_with_binary_operator .__code__ .co_firstlineno
658+ expected_error = (
659+ 'Traceback (most recent call last):\n '
660+ f' File "{ __file__ } ", line { self .callable_line } , in get_exception\n '
661+ ' callable()\n '
662+ f' File "{ __file__ } ", line { lineno_f + 3 } , in f_with_binary_operator\n '
663+ ' return b [ a ] + c\n '
664+ ' ~~~~~~^^^^^^^^^\n '
665+ )
666+ result_lines = self .get_exception (f_with_binary_operator )
667+ self .assertEqual (result_lines , expected_error .splitlines ())
668+
633669 def test_traceback_specialization_with_syntax_error (self ):
634670 bytecode = compile ("1 / 0 / 1 / 2\n " , TESTFN , "exec" )
635671
0 commit comments