mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
bpo-30529: Fix errors for invalid whitespaces in f-string subexpressions. (#1888)
'invalid character in identifier' now is raised instead of 'f-string: empty expression not allowed' if a subexpression contains only whitespaces and they are not accepted by Python parser.
This commit is contained in:
parent
29adc13bd7
commit
2e9cd5825c
2 changed files with 17 additions and 24 deletions
|
@ -280,6 +280,10 @@ f'{a * x()}'"""
|
|||
"f'{10:{ }}'",
|
||||
"f' { } '",
|
||||
|
||||
# The Python parser ignores also the following
|
||||
# whitespace characters in additional to a space.
|
||||
"f'''{\t\f\r\n}'''",
|
||||
|
||||
# Catch the empty expression before the
|
||||
# invalid conversion.
|
||||
"f'{!x}'",
|
||||
|
@ -300,6 +304,12 @@ f'{a * x()}'"""
|
|||
"f'{:x'",
|
||||
])
|
||||
|
||||
# Different error message is raised for other whitespace characters.
|
||||
self.assertAllRaise(SyntaxError, 'invalid character in identifier',
|
||||
["f'''{\xa0}'''",
|
||||
"\xa0",
|
||||
])
|
||||
|
||||
def test_parens_in_expressions(self):
|
||||
self.assertEqual(f'{3,}', '(3,)')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue