summaryrefslogtreecommitdiff
path: root/Lib/test/test_fstring.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-09 00:38:06 +0300
committerGitHub <noreply@github.com>2017-06-09 00:38:06 +0300
commit570b1c971c31cd08dbf060f4e21636c40aa47786 (patch)
treef13cb58e5792e0a969e4dc6c59f0624ec9b9cbe2 /Lib/test/test_fstring.py
parentb319d09ee4427aac1ee8f298692127d34ef57dc0 (diff)
downloadcpython-git-570b1c971c31cd08dbf060f4e21636c40aa47786.tar.gz
[3.6] bpo-30529: Fix errors for invalid whitespaces in f-string subexpressions. (GH-1888) (#2013)
'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. (cherry picked from commit 2e9cd58)
Diffstat (limited to 'Lib/test/test_fstring.py')
-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 25730029ae..b39870457a 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,)')