Move f-string compilation of the expression earlier, before the conversion character and format_spec are checked. This allows for error messages that more closely match what a user would expect.

This commit is contained in:
Eric V. Smith 2015-09-23 07:49:00 -04:00
parent 3a1a8d0424
commit 1d44c41b0c
2 changed files with 60 additions and 15 deletions

View file

@ -287,6 +287,15 @@ f'{a * x()}'"""
"f' { } '",
r"f'{\n}'",
r"f'{\n \n}'",
# Catch the empty expression before the
# invalid conversion.
"f'{!x}'",
"f'{ !xr}'",
"f'{!x:}'",
"f'{!x:a}'",
"f'{ !xr:}'",
"f'{ !xr:a}'",
])
def test_parens_in_expressions(self):