Skip to content

Commit 09835dc

Browse files
committed
Make an f-string error message more exact and consistent.
1 parent 13a6d28 commit 09835dc

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

Lib/test/test_fstring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ def test_comments(self):
182182
self.assertEqual(f'{"#"}', '#')
183183
self.assertEqual(f'{d["#"]}', 'hash')
184184

185-
self.assertAllRaise(SyntaxError, "f-string cannot include '#'",
185+
self.assertAllRaise(SyntaxError, "f-string expression part cannot include '#'",
186186
["f'{1#}'", # error because the expression becomes "(1#)"
187187
"f'{3(#)}'",
188+
"f'{#}'",
188189
])
189190

190191
def test_many_expressions(self):

Python/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4419,7 +4419,7 @@ fstring_find_expr(const char **str, const char *end, int raw, int recurse_lvl,
44194419
} else if (ch == '#') {
44204420
/* Error: can't include a comment character, inside parens
44214421
or not. */
4422-
ast_error(c, n, "f-string cannot include '#'");
4422+
ast_error(c, n, "f-string expression part cannot include '#'");
44234423
return -1;
44244424
} else if (nested_depth == 0 &&
44254425
(ch == '!' || ch == ':' || ch == '}')) {

0 commit comments

Comments
 (0)