]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40246: Revert reporting of invalid string prefixes (GH-19888)
authorLysandros Nikolaou <lisandrosnik@gmail.com>
Mon, 4 May 2020 11:32:18 +0000 (14:32 +0300)
committerGitHub <noreply@github.com>
Mon, 4 May 2020 11:32:18 +0000 (12:32 +0100)
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 41d5b94af44e34ac05d4cd57460ed104ccf96628 has to be reverted.

Include/errcode.h
Lib/test/test_fstring.py
Misc/NEWS.d/next/Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst [new file with mode: 0644]
Parser/pegen/pegen.c
Parser/tokenizer.c
Python/pythonrun.c

index 9af8d5c03d59ba0259fd7c94319a8e7f981f04e7..b37cd261d5ec4d54ac6b8ca9fd6008e70e35859a 100644 (file)
@@ -31,7 +31,6 @@ 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
 }
index fe465b7e1d43dc7bb5ae264b8b7929f4ab5d6c03..ac5aa9a76efe7cefcf1911dc16d2138f1524f715 100644 (file)
@@ -864,7 +864,7 @@ non-important content
                              "Bf''",
                              "BF''",]
         double_quote_cases = [case.replace("'", '"') for case in single_quote_cases]
-        self.assertAllRaise(SyntaxError, 'invalid string prefix',
+        self.assertAllRaise(SyntaxError, 'unexpected EOF while parsing',
                             single_quote_cases + double_quote_cases)
 
     def test_leading_trailing_spaces(self):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst
new file mode 100644 (file)
index 0000000..62cd632
--- /dev/null
@@ -0,0 +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.
index 391f9b91eab902deeb73e41f23109d28fec7738d..c311593af70f58ea1a2d0c4a8c131038b74ddb35 100644 (file)
@@ -334,9 +334,6 @@ tokenizer_error(Parser *p)
         case E_IDENTIFIER:
             msg = "invalid character in identifier";
             break;
-        case E_BADPREFIX:
-            RAISE_SYNTAX_ERROR("invalid string prefix");
-            return -1;
         case E_EOFS:
             RAISE_SYNTAX_ERROR("EOF while scanning triple-quoted string literal");
             return -1;
index 95dfc5388037d02eeffcdf29239987b09a9a79b0..0f2b6af5e50adfac9fdcf063a944a99923d1959a 100644 (file)
@@ -1396,10 +1396,6 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end)
         *p_start = tok->start;
         *p_end = tok->cur;
 
-        if (c == '"' || c == '\'') {
-            tok->done = E_BADPREFIX;
-            return ERRORTOKEN;
-        }
         /* async/await parsing block. */
         if (tok->cur - tok->start == 5 && tok->start[0] == 'a') {
             /* May be an 'async' or 'await' token.  For Python 3.7 or
index 79147e430a1ad74e1b1c5d1358481fa446bff308..1b79a33c814da157e0bb49814422c7f4b6027b37 100644 (file)
@@ -1609,9 +1609,6 @@ 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";