Skip to content

Commit 846d8b2

Browse files
authored
bpo-40246: Revert reporting of invalid string prefixes (GH-19888)
Due to backwards compatibility concerns regarding keywords immediately followed by a string without whitespace between them (like in `bg="#d00" if clear else"#fca"`) will fail to parse, commit 41d5b94 has to be reverted.
1 parent e10e7c7 commit 846d8b2

File tree

6 files changed

+2
-12
lines changed

6 files changed

+2
-12
lines changed

Include/errcode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ extern "C" {
3131
#define E_LINECONT 25 /* Unexpected characters after a line continuation */
3232
#define E_IDENTIFIER 26 /* Invalid characters in identifier */
3333
#define E_BADSINGLE 27 /* Ill-formed single statement input */
34-
#define E_BADPREFIX 28 /* Bad string prefixes */
3534

3635
#ifdef __cplusplus
3736
}

Lib/test/test_fstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def test_invalid_string_prefixes(self):
864864
"Bf''",
865865
"BF''",]
866866
double_quote_cases = [case.replace("'", '"') for case in single_quote_cases]
867-
self.assertAllRaise(SyntaxError, 'invalid string prefix',
867+
self.assertAllRaise(SyntaxError, 'unexpected EOF while parsing',
868868
single_quote_cases + double_quote_cases)
869869

870870
def test_leading_trailing_spaces(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reporting a specialised error message for invalid string prefixes, which was introduced in :issue:`40246`, is being reverted due to backwards compatibility concerns for strings that immediately follow a reserved keyword without whitespace between them. Constructs like `bg="#d00" if clear else"#fca"` were failing to parse, which is not an acceptable breakage on such short notice.

Parser/pegen/pegen.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,6 @@ tokenizer_error(Parser *p)
334334
case E_IDENTIFIER:
335335
msg = "invalid character in identifier";
336336
break;
337-
case E_BADPREFIX:
338-
RAISE_SYNTAX_ERROR("invalid string prefix");
339-
return -1;
340337
case E_EOFS:
341338
RAISE_SYNTAX_ERROR("EOF while scanning triple-quoted string literal");
342339
return -1;

Parser/tokenizer.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,10 +1396,6 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end)
13961396
*p_start = tok->start;
13971397
*p_end = tok->cur;
13981398

1399-
if (c == '"' || c == '\'') {
1400-
tok->done = E_BADPREFIX;
1401-
return ERRORTOKEN;
1402-
}
14031399
/* async/await parsing block. */
14041400
if (tok->cur - tok->start == 5 && tok->start[0] == 'a') {
14051401
/* May be an 'async' or 'await' token. For Python 3.7 or

Python/pythonrun.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,9 +1609,6 @@ err_input(perrdetail *err)
16091609
case E_BADSINGLE:
16101610
msg = "multiple statements found while compiling a single statement";
16111611
break;
1612-
case E_BADPREFIX:
1613-
msg = "invalid string prefix";
1614-
break;
16151612
default:
16161613
fprintf(stderr, "error=%d\n", err->error);
16171614
msg = "unknown parsing error";

0 commit comments

Comments
 (0)