[Python-checkins] gh-100050: Fix an assertion error when raising unclosed parenthesis errors in the tokenizer (GH-100065)
miss-islington
webhook-mailer at python.org
Wed Dec 7 04:18:41 EST 2022
https://github.com/python/cpython/commit/2b97ddd5122c016bd090ed187479606205b6b1a4
commit: 2b97ddd5122c016bd090ed187479606205b6b1a4
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-12-07T01:18:00-08:00
summary:
gh-100050: Fix an assertion error when raising unclosed parenthesis errors in the tokenizer (GH-100065)
(cherry picked from commit 97e7004cfe48305bcd642c653b406dc7470e196d)
Co-authored-by: Pablo Galindo Salgado <Pablogsal at gmail.com>
Automerge-Triggered-By: GH:pablogsal
files:
A Misc/NEWS.d/next/Core and Builtins/2022-12-06-22-24-01.gh-issue-100050.lcrPqQ.rst
M Lib/test/test_syntax.py
M Parser/pegen_errors.c
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 400092ee2c89..42d36e0b9d81 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -2095,6 +2095,22 @@ def test_error_parenthesis(self):
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_invisible_characters(self):
self._check_error('print\x17("Hello")', "invalid non-printable character")
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
index 000000000000..8e7c72d804f8
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-06-22-24-01.gh-issue-100050.lcrPqQ.rst
@@ -0,0 +1,2 @@
+Honor existing errors obtained when searching for mismatching parentheses in
+the tokenizer. Patch by Pablo Galindo
diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c
index a0f4b9809e21..3d8cccb0a974 100644
--- a/Parser/pegen_errors.c
+++ b/Parser/pegen_errors.c
@@ -170,6 +170,10 @@ _PyPegen_tokenize_full_source_to_check_for_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) {
More information about the Python-checkins
mailing list