]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] gh-100050: Fix an assertion error when raising unclosed parenthesis errors...
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Wed, 7 Dec 2022 13:52:05 +0000 (13:52 +0000)
committerGitHub <noreply@github.com>
Wed, 7 Dec 2022 13:52:05 +0000 (13:52 +0000)
Automerge-Triggered-By: GH:pablogsal.
(cherry picked from commit 97e7004cfe48305bcd642c653b406dc7470e196d)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Lib/test/test_syntax.py
Misc/NEWS.d/next/Core and Builtins/2022-12-06-22-24-01.gh-issue-100050.lcrPqQ.rst [new file with mode: 0644]
Parser/pegen.c

index 5f2528b904b5f3b2f27c158ea7ebd7226ee56efb..cd09d1eabdf5dbe1ffb71adeb3f46ac901352006 100644 (file)
@@ -1587,6 +1587,22 @@ def func2():
         for paren in ")]}":
             self._check_error(paren + "1 + 2", f"unmatched '\\{paren}'")
 
+        # Some more complex examples:
+        code = """\
+func(
+    a=["unclosed], # Need a quote in this comment: "
+    b=2,
+)
+"""
+        self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['")
+
+    def test_error_string_literal(self):
+
+        self._check_error("'blech", "unterminated string literal")
+        self._check_error('"blech', "unterminated string literal")
+        self._check_error("'''blech", "unterminated triple-quoted string literal")
+        self._check_error('"""blech', "unterminated triple-quoted string literal")
+
     def test_match_call_does_not_raise_syntax_error(self):
         code = """
 def match(x):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-06-22-24-01.gh-issue-100050.lcrPqQ.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-06-22-24-01.gh-issue-100050.lcrPqQ.rst
new file mode 100644 (file)
index 0000000..8e7c72d
--- /dev/null
@@ -0,0 +1,2 @@
+Honor existing errors obtained when searching for mismatching parentheses in
+the tokenizer. Patch by Pablo Galindo
index c12adedebba37e8d406ef839aa8991be6a7108b2..95c2273e4b42cf4562a31f6920920d8b951f4ebf 100644 (file)
@@ -1328,6 +1328,10 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
         const char *end;
         switch (PyTokenizer_Get(p->tok, &start, &end)) {
             case ERRORTOKEN:
+                if (PyErr_Occurred()) {
+                    ret = -1;
+                    goto exit;
+                }
                 if (p->tok->level != 0) {
                     int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
                     if (current_err_line > error_lineno) {