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:
Serhiy Storchaka 2017-06-08 23:43:54 +03:00 committed by GitHub
parent 29adc13bd7
commit 2e9cd5825c
2 changed files with 17 additions and 24 deletions

View file

@ -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,)')