From 1c3eeaace8c54c6e5dd96e92c1e1186994d2a1e7 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Sun, 3 May 2020 23:26:48 +0300 Subject: [PATCH 1/4] bpo-40246: Revert reporting of invalid string prefixes Due to backwards compatibility concerns, that keywords immediately followed by a string without whitespace between them (like in `bg="#d00" if clear else"#fca"`) will fail to parse, PR19476 has to be reverted. --- Include/errcode.h | 1 - Lib/test/test_fstring.py | 2 +- Parser/pegen/pegen.c | 3 --- Parser/tokenizer.c | 4 ---- Python/pythonrun.c | 3 --- 5 files changed, 1 insertion(+), 12 deletions(-) diff --git a/Include/errcode.h b/Include/errcode.h index 9af8d5c03d59ba0..b37cd261d5ec4d5 100644 --- a/Include/errcode.h +++ b/Include/errcode.h @@ -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 } diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index fe465b7e1d43dc7..ac5aa9a76efe7ce 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -864,7 +864,7 @@ def test_invalid_string_prefixes(self): "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/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index 6ff09b3b31f783d..ac6588db48cb82c 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -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; diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 95dfc5388037d02..0f2b6af5e50adfa 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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 diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 79147e430a1ad74..1b79a33c814da15 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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"; From ea8beec6da12fcb1a706cf88e03a18f96d2b791a Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 3 May 2020 23:28:15 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst 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 index 000000000000000..d0a9e7e5c50c2a3 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst @@ -0,0 +1 @@ +Reporting a specialised error message for invalid string prefixes, which was introduced in #19888, 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. \ No newline at end of file From d117a60190813ba10c9e5609d963bf69bb8f3af9 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Mon, 4 May 2020 02:38:18 +0300 Subject: [PATCH 3/4] Correct PR number in NEWS file --- .../Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index d0a9e7e5c50c2a3..e66921b37654694 100644 --- 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 @@ -1 +1 @@ -Reporting a specialised error message for invalid string prefixes, which was introduced in #19888, 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. \ No newline at end of file +Reporting a specialised error message for invalid string prefixes, which was introduced in GH-19476, 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. From 9657bbd0b98284f800ad34a4cce6d1a5821c0d03 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Mon, 4 May 2020 14:05:11 +0300 Subject: [PATCH 4/4] Use issue number instead of PR number Co-authored-by: Pablo Galindo --- .../Core and Builtins/2020-05-03-23-28-11.bpo-40246.c1D7x8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index e66921b37654694..62cd632ffd07077 100644 --- 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 @@ -1 +1 @@ -Reporting a specialised error message for invalid string prefixes, which was introduced in GH-19476, 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. +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.