Skip to content

Commit

Permalink
Remove "f-string: " prefix from regular syntax errors
Browse files Browse the repository at this point in the history
If a syntax error is not specific to the situation of an f-string
(like empty expression etc.) then it probably doesn't worth the
extra complexity for us to introduce codepaths in tokenizer in
order to add an "f-string" prefix in front of the errors.
  • Loading branch information
isidentical committed Mar 25, 2023
1 parent 081f5a2 commit 307f7d2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,31 +481,31 @@ def test_literal(self):
self.assertEqual(f' ', ' ')

def test_unterminated_string(self):
self.assertAllRaise(SyntaxError, 'f-string: unterminated string',
self.assertAllRaise(SyntaxError, 'unterminated string',
[r"""f'{"x'""",
r"""f'{"x}'""",
r"""f'{("x'""",
r"""f'{("x}'""",
])

def test_mismatched_parens(self):
self.assertAllRaise(SyntaxError, r"f-string: closing parenthesis '\}' "
self.assertAllRaise(SyntaxError, r"closing parenthesis '\}' "
r"does not match opening parenthesis '\('",
["f'{((}'",
])
self.assertAllRaise(SyntaxError, r"f-string: closing parenthesis '\)' "
self.assertAllRaise(SyntaxError, r"closing parenthesis '\)' "
r"does not match opening parenthesis '\['",
["f'{a[4)}'",
])
self.assertAllRaise(SyntaxError, r"f-string: closing parenthesis '\]' "
self.assertAllRaise(SyntaxError, r"closing parenthesis '\]' "
r"does not match opening parenthesis '\('",
["f'{a(4]}'",
])
self.assertAllRaise(SyntaxError, r"f-string: closing parenthesis '\}' "
self.assertAllRaise(SyntaxError, r"closing parenthesis '\}' "
r"does not match opening parenthesis '\['",
["f'{a[4}'",
])
self.assertAllRaise(SyntaxError, r"f-string: closing parenthesis '\}' "
self.assertAllRaise(SyntaxError, r"closing parenthesis '\}' "
r"does not match opening parenthesis '\('",
["f'{a(4}'",
])
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_compile_time_concat(self):
self.assertEqual(f'' '' f'', '')
self.assertEqual(f'' '' f'' '', '')

self.assertAllRaise(SyntaxError, "f-string: expecting '}'",
self.assertAllRaise(SyntaxError, "expecting '}'",
["f'{3' f'}'", # can't concat to get a valid f-string
])

Expand Down Expand Up @@ -729,12 +729,12 @@ def test_parens_in_expressions(self):
# are added around it. But we shouldn't go from an invalid
# expression to a valid one. The added parens are just
# supposed to allow whitespace (including newlines).
self.assertAllRaise(SyntaxError, 'f-string: invalid syntax',
self.assertAllRaise(SyntaxError, 'invalid syntax',
["f'{,}'",
"f'{,}'", # this is (,), which is an error
])

self.assertAllRaise(SyntaxError, r"f-string: unmatched '\)'",
self.assertAllRaise(SyntaxError, r"closing parenthesis '\)' does not",
["f'{3)+(4}'",
])

Expand Down

0 comments on commit 307f7d2

Please sign in to comment.