Skip to content

Commit 72cfe5b

Browse files
authored
[3.10] gh-100050: Fix an assertion error when raising unclosed parenthesis errors in the tokenizer (GH-100065) (#100073)
Automerge-Triggered-By: GH:pablogsal. (cherry picked from commit 97e7004) Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent 3843973 commit 72cfe5b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Lib/test/test_syntax.py

+16
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,22 @@ def test_error_parenthesis(self):
15871587
for paren in ")]}":
15881588
self._check_error(paren + "1 + 2", f"unmatched '\\{paren}'")
15891589

1590+
# Some more complex examples:
1591+
code = """\
1592+
func(
1593+
a=["unclosed], # Need a quote in this comment: "
1594+
b=2,
1595+
)
1596+
"""
1597+
self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['")
1598+
1599+
def test_error_string_literal(self):
1600+
1601+
self._check_error("'blech", "unterminated string literal")
1602+
self._check_error('"blech', "unterminated string literal")
1603+
self._check_error("'''blech", "unterminated triple-quoted string literal")
1604+
self._check_error('"""blech', "unterminated triple-quoted string literal")
1605+
15901606
def test_match_call_does_not_raise_syntax_error(self):
15911607
code = """
15921608
def match(x):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Honor existing errors obtained when searching for mismatching parentheses in
2+
the tokenizer. Patch by Pablo Galindo

Parser/pegen.c

+4
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,10 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
13281328
const char *end;
13291329
switch (PyTokenizer_Get(p->tok, &start, &end)) {
13301330
case ERRORTOKEN:
1331+
if (PyErr_Occurred()) {
1332+
ret = -1;
1333+
goto exit;
1334+
}
13311335
if (p->tok->level != 0) {
13321336
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
13331337
if (current_err_line > error_lineno) {

0 commit comments

Comments
 (0)