@@ -524,7 +524,7 @@ def test_format_specifier_expressions(self):
524524 # This looks like a nested format spec.
525525 ])
526526
527- self .assertAllRaise (SyntaxError , "invalid syntax" ,
527+ self .assertAllRaise (SyntaxError , "f-string: invalid syntax" ,
528528 [# Invalid syntax inside a nested spec.
529529 "f'{4:{/5}}'" ,
530530 ])
@@ -598,7 +598,7 @@ def test_parens_in_expressions(self):
598598 # are added around it. But we shouldn't go from an invalid
599599 # expression to a valid one. The added parens are just
600600 # supposed to allow whitespace (including newlines).
601- self .assertAllRaise (SyntaxError , 'invalid syntax' ,
601+ self .assertAllRaise (SyntaxError , 'f-string: invalid syntax' ,
602602 ["f'{,}'" ,
603603 "f'{,}'" , # this is (,), which is an error
604604 ])
@@ -716,7 +716,7 @@ def test_lambda(self):
716716
717717 # lambda doesn't work without parens, because the colon
718718 # makes the parser think it's a format_spec
719- self .assertAllRaise (SyntaxError , 'invalid syntax' ,
719+ self .assertAllRaise (SyntaxError , 'f-string: invalid syntax' ,
720720 ["f'{lambda x:x}'" ,
721721 ])
722722
@@ -1194,6 +1194,10 @@ def test_walrus(self):
11941194 self .assertEqual (f'{ (x := 10 )} ' , '10' )
11951195 self .assertEqual (x , 10 )
11961196
1197+ def test_invalid_syntax_error_message (self ):
1198+ with self .assertRaisesRegex (SyntaxError , "f-string: invalid syntax" ):
1199+ compile ("f'{a $ b}'" , "?" , "exec" )
1200+
11971201
11981202if __name__ == '__main__' :
11991203 unittest .main ()
0 commit comments