Skip to content

[3.11] gh-100050: Fix an assertion error when raising unclosed parenthesis errors in the tokenizer (GH-100065) #100067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Honor existing errors obtained when searching for mismatching parentheses in
the tokenizer. Patch by Pablo Galindo
4 changes: 4 additions & 0 deletions Parser/pegen_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down