[Python-checkins] cpython: Make an f-string error message more exact and consistent.

eric.smith python-checkins at python.org
Sun Sep 11 18:58:24 EDT 2016


https://hg.python.org/cpython/rev/3992c7f690e1
changeset:   103666:3992c7f690e1
user:        Eric V. Smith <eric at trueblade.com>
date:        Sun Sep 11 18:58:20 2016 -0400
summary:
  Make an f-string error message more exact and consistent.

files:
  Lib/test/test_fstring.py |  3 ++-
  Python/ast.c             |  2 +-
  2 files changed, 3 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -182,9 +182,10 @@
         self.assertEqual(f'{"#"}', '#')
         self.assertEqual(f'{d["#"]}', 'hash')
 
-        self.assertAllRaise(SyntaxError, "f-string cannot include '#'",
+        self.assertAllRaise(SyntaxError, "f-string expression part cannot include '#'",
                             ["f'{1#}'",   # error because the expression becomes "(1#)"
                              "f'{3(#)}'",
+                             "f'{#}'",
                              ])
 
     def test_many_expressions(self):
diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -4419,7 +4419,7 @@
         } else if (ch == '#') {
             /* Error: can't include a comment character, inside parens
                or not. */
-            ast_error(c, n, "f-string cannot include '#'");
+            ast_error(c, n, "f-string expression part cannot include '#'");
             return -1;
         } else if (nested_depth == 0 &&
                    (ch == '!' || ch == ':' || ch == '}')) {

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list