diff options
author | Maciej Górski <36813763+macgors@users.noreply.github.com> | 2022-03-28 21:08:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-28 21:08:36 (GMT) |
commit | 7b44ade018cfe6f54002a3cee43e8aa415d4d635 (patch) | |
tree | 07816d9022fea4b902b69026360d912167410daf /Lib/test/test_fstring.py | |
parent | 15ba8167d78f9e66bd5b07c4e5cbb0463460310a (diff) | |
download | cpython-7b44ade018cfe6f54002a3cee43e8aa415d4d635.zip cpython-7b44ade018cfe6f54002a3cee43e8aa415d4d635.tar.gz cpython-7b44ade018cfe6f54002a3cee43e8aa415d4d635.tar.bz2 |
bpo-47129: Add more informative messages to f-string syntax errors (32127)
* Add more informative messages to f-string syntax errors
* 📜🤖 Added by blurb_it.
* Fix whitespaces
* Change error message
* Remove the 'else' statement (as sugested in review)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_fstring.py')
-rw-r--r-- | Lib/test/test_fstring.py | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 0c255c2..0c3372f 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -628,16 +628,27 @@ x = ( ["f'{}'", "f'{ }'" "f' {} '", - "f'{!r}'", - "f'{ !r}'", "f'{10:{ }}'", "f' { } '", # The Python parser ignores also the following # whitespace characters in additional to a space. "f'''{\t\f\r\n}'''", + ]) + + # Different error messeges are raised when a specfier ('!', ':' or '=') is used after an empty expression + self.assertAllRaise(SyntaxError, "f-string: expression required before '!'", + ["f'{!r}'", + "f'{ !r}'", + "f'{!}'", + "f'''{\t\f\r\n!a}'''", + + # Catch empty expression before the + # missing closing brace. + "f'{!'", + "f'{!s:'", - # Catch the empty expression before the + # Catch empty expression before the # invalid conversion. "f'{!x}'", "f'{ !xr}'", @@ -645,16 +656,23 @@ x = ( "f'{!x:a}'", "f'{ !xr:}'", "f'{ !xr:a}'", + ]) - "f'{!}'", - "f'{:}'", - - # We find the empty expression before the - # missing closing brace. - "f'{!'", - "f'{!s:'", + self.assertAllRaise(SyntaxError, "f-string: expression required before ':'", + ["f'{:}'", + "f'{ :!}'", + "f'{:2}'", + "f'''{\t\f\r\n:a}'''", "f'{:'", - "f'{:x'", + ]) + + self.assertAllRaise(SyntaxError, "f-string: expression required before '='", + ["f'{=}'", + "f'{ =}'", + "f'{ =:}'", + "f'{ =!}'", + "f'''{\t\f\r\n=}'''", + "f'{='", ]) # Different error message is raised for other whitespace characters. |