]> granicus.if.org Git - python/commitdiff
Make an f-string error message more exact and consistent.
authorEric V. Smith <eric@trueblade.com>
Sun, 11 Sep 2016 22:58:20 +0000 (18:58 -0400)
committerEric V. Smith <eric@trueblade.com>
Sun, 11 Sep 2016 22:58:20 +0000 (18:58 -0400)
Lib/test/test_fstring.py
Python/ast.c

index e61f63594fab4a4b54a705388f6820d21b892bdd..655819425d13ff39a7e50ebb990e1bdb34193f29 100644 (file)
@@ -182,9 +182,10 @@ f'{a * x()}'"""
         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):
index 092031cc8c443ea226aafe5e4694e734fae6bf04..765d24e11b89abb5d3197863f4087cfda1606023 100644 (file)
@@ -4419,7 +4419,7 @@ fstring_find_expr(const char **str, const char *end, int raw, int recurse_lvl,
         } 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 == '}')) {