[Python-checkins] bpo-43822: Prioritize tokenizer errors over custom syntax errors when raising parser exceptions (GH-25866)
miss-islington
webhook-mailer at python.org
Mon May 3 21:06:52 EDT 2021
https://github.com/python/cpython/commit/756b7b9248885d65c2b3b9f1c5a8f66aa2e8de7a
commit: 756b7b9248885d65c2b3b9f1c5a8f66aa2e8de7a
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-05-03T18:06:45-07:00
summary:
bpo-43822: Prioritize tokenizer errors over custom syntax errors when raising parser exceptions (GH-25866)
(cherry picked from commit 9142088e7454a392b69a627863b235ecc32aea54)
Co-authored-by: Pablo Galindo <Pablogsal at gmail.com>
files:
A Misc/NEWS.d/next/Core and Builtins/2021-05-04-01-01-04.bpo-43822.9VeCg0.rst
M Lib/test/test_exceptions.py
M Parser/pegen.c
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index bc0404ea4b04d5..3c427fed561183 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -210,7 +210,7 @@ def testSyntaxErrorOffset(self):
check('x = "a', 1, 5)
check('lambda x: x = 2', 1, 1)
check('f{a + b + c}', 1, 2)
- check('[file for str(file) in []\n])', 1, 11)
+ check('[file for str(file) in []\n])', 2, 2)
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)
check('[file for\n str(file) in []]', 2, 2)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-05-04-01-01-04.bpo-43822.9VeCg0.rst b/Misc/NEWS.d/next/Core and Builtins/2021-05-04-01-01-04.bpo-43822.9VeCg0.rst
new file mode 100644
index 00000000000000..b8815cddf4e2c1
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-05-04-01-01-04.bpo-43822.9VeCg0.rst
@@ -0,0 +1,2 @@
+The parser will prioritize tokenizer errors over custom syntax errors when
+raising exceptions. Patch by Pablo Galindo.
diff --git a/Parser/pegen.c b/Parser/pegen.c
index e32b2710dbda26..6080cec1489ed8 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1283,6 +1283,9 @@ _PyPegen_run_parser(Parser *p)
reset_parser_state(p);
_PyPegen_parse(p);
if (PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_SyntaxError)) {
+ _PyPegen_check_tokenizer_errors(p);
+ }
return NULL;
}
if (p->fill == 0) {
More information about the Python-checkins
mailing list