summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-08 20:43:54 (GMT)
committerGitHub <noreply@github.com>2017-06-08 20:43:54 (GMT)
commit2e9cd5825c5ccdbb6f65a57c0c7941078e003c14 (patch)
tree1f39984ce8de33ad6f1da69e34e5e09b9161823c /Lib
parent29adc13bd797d9c9e7fcb893a7c49ce7f7ad388c (diff)
downloadcpython-2e9cd5825c5ccdbb6f65a57c0c7941078e003c14.zip
cpython-2e9cd5825c5ccdbb6f65a57c0c7941078e003c14.tar.gz
cpython-2e9cd5825c5ccdbb6f65a57c0c7941078e003c14.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_fstring.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 2573002..b398704 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -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,)')