Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/errcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" {
#define E_LINECONT 25 /* Unexpected characters after a line continuation */
#define E_IDENTIFIER 26 /* Invalid characters in identifier */
#define E_BADSINGLE 27 /* Ill-formed single statement input */
#define E_BADPREFIX 28 /* Bad string prefixes */

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def test_nested_fstrings(self):
self.assertEqual(f'{f"{y}"*3}', '555')

def test_invalid_string_prefixes(self):
self.assertAllRaise(SyntaxError, 'unexpected EOF while parsing',
self.assertAllRaise(SyntaxError, 'invalid string prefix',
["fu''",
"uf''",
"Fu''",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Report a specialized error message, `invalid string prefix`, when the tokenizer encounters a string with an invalid prefix.
4 changes: 4 additions & 0 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,10 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end)
if (nonascii && !verify_identifier(tok)) {
return ERRORTOKEN;
}
if (c == '"' || c == '\'') {
tok->done = E_BADPREFIX;
return ERRORTOKEN;
}
*p_start = tok->start;
*p_end = tok->cur;

Expand Down
3 changes: 3 additions & 0 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,9 @@ err_input(perrdetail *err)
case E_BADSINGLE:
msg = "multiple statements found while compiling a single statement";
break;
case E_BADPREFIX:
msg = "invalid string prefix";
break;
default:
fprintf(stderr, "error=%d\n", err->error);
msg = "unknown parsing error";
Expand Down