From 09835dcdbb8bb9c5f355ed55d2fa8c0d140ee7ee Mon Sep 17 00:00:00 2001 From: "Eric V. Smith" Date: Sun, 11 Sep 2016 18:58:20 -0400 Subject: Make an f-string error message more exact and consistent. --- 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 index e61f635..6558194 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -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): diff --git a/Python/ast.c b/Python/ast.c index 092031c..765d24e 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -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 == '}')) { -- cgit v0.12