]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43822: Prioritize tokenizer errors over custom syntax errors when raising parser...
authorPablo Galindo <Pablogsal@gmail.com>
Tue, 4 May 2021 00:32:46 +0000 (01:32 +0100)
committerGitHub <noreply@github.com>
Tue, 4 May 2021 00:32:46 +0000 (01:32 +0100)
Lib/test/test_exceptions.py
Misc/NEWS.d/next/Core and Builtins/2021-05-04-01-01-04.bpo-43822.9VeCg0.rst [new file with mode: 0644]
Parser/pegen.c

index bc0404ea4b04d53261f387fa4aaf140c9c1bb8e5..3c427fed5611832d986b85caa845b3c23b8d20ee 100644 (file)
@@ -210,7 +210,7 @@ class ExceptionTests(unittest.TestCase):
         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 (file)
index 0000000..b8815cd
--- /dev/null
@@ -0,0 +1,2 @@
+The parser will prioritize tokenizer errors over custom syntax errors when
+raising exceptions. Patch by Pablo Galindo.
index e32b2710dbda261d4f06b132e571753b895ab1f1..6080cec1489ed802a25c28f1571d4163f29b8184 100644 (file)
@@ -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) {