Skip to content

Commit 990efe0

Browse files
authored
[3.9] bpo-41084: Fix test_fstring failure when using the old parser (GH-21212)
1 parent a3f2a58 commit 990efe0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Lib/test/test_fstring.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ def test_format_specifier_expressions(self):
524524
# This looks like a nested format spec.
525525
])
526526

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,
528529
[# Invalid syntax inside a nested spec.
529530
"f'{4:{/5}}'",
530531
])
@@ -598,7 +599,8 @@ def test_parens_in_expressions(self):
598599
# are added around it. But we shouldn't go from an invalid
599600
# expression to a valid one. The added parens are just
600601
# 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,
602604
["f'{,}'",
603605
"f'{,}'", # this is (,), which is an error
604606
])
@@ -716,7 +718,8 @@ def test_lambda(self):
716718

717719
# lambda doesn't work without parens, because the colon
718720
# 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,
720723
["f'{lambda x:x}'",
721724
])
722725

@@ -1201,7 +1204,8 @@ def test_walrus(self):
12011204
self.assertEqual(x, 10)
12021205

12031206
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):
12051209
compile("f'{a $ b}'", "?", "exec")
12061210

12071211

0 commit comments

Comments
 (0)