@@ -524,7 +524,8 @@ def test_format_specifier_expressions(self):
524
524
# This looks like a nested format spec.
525
525
])
526
526
527
- self .assertAllRaise (SyntaxError , "f-string: invalid syntax" ,
527
+ err_msg = "invalid syntax" if use_old_parser () else "f-string: invalid syntax"
528
+ self .assertAllRaise (SyntaxError , err_msg ,
528
529
[# Invalid syntax inside a nested spec.
529
530
"f'{4:{/5}}'" ,
530
531
])
@@ -598,7 +599,8 @@ def test_parens_in_expressions(self):
598
599
# are added around it. But we shouldn't go from an invalid
599
600
# expression to a valid one. The added parens are just
600
601
# supposed to allow whitespace (including newlines).
601
- self .assertAllRaise (SyntaxError , 'f-string: invalid syntax' ,
602
+ err_msg = "invalid syntax" if use_old_parser () else "f-string: invalid syntax"
603
+ self .assertAllRaise (SyntaxError , err_msg ,
602
604
["f'{,}'" ,
603
605
"f'{,}'" , # this is (,), which is an error
604
606
])
@@ -716,7 +718,8 @@ def test_lambda(self):
716
718
717
719
# lambda doesn't work without parens, because the colon
718
720
# makes the parser think it's a format_spec
719
- self .assertAllRaise (SyntaxError , 'f-string: invalid syntax' ,
721
+ err_msg = "invalid syntax" if use_old_parser () else "f-string: invalid syntax"
722
+ self .assertAllRaise (SyntaxError , err_msg ,
720
723
["f'{lambda x:x}'" ,
721
724
])
722
725
@@ -1201,7 +1204,8 @@ def test_walrus(self):
1201
1204
self .assertEqual (x , 10 )
1202
1205
1203
1206
def test_invalid_syntax_error_message (self ):
1204
- with self .assertRaisesRegex (SyntaxError , "f-string: invalid syntax" ):
1207
+ err_msg = "invalid syntax" if use_old_parser () else "f-string: invalid syntax"
1208
+ with self .assertRaisesRegex (SyntaxError , err_msg ):
1205
1209
compile ("f'{a $ b}'" , "?" , "exec" )
1206
1210
1207
1211
0 commit comments