[3.10] bpo-45727: Only trigger the 'did you forgot a comma' error suggestion if inside parentheses. (GH-29767)
Backport of GH-29757
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 8946aa3..e37aaf7 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -692,6 +692,8 @@
return -1;
}
+ token->level = p->tok->level;
+
const char *line_start = token_type == STRING ? p->tok->multi_line_start : p->tok->line_start;
int lineno = token_type == STRING ? p->tok->first_lineno : p->tok->lineno;
int end_lineno = p->tok->lineno;
@@ -1357,7 +1359,7 @@
if (p->fill == 0) {
RAISE_SYNTAX_ERROR("error at start before reading any input");
}
- else if (p->tok->done == E_EOF) {
+ else if (last_token->type == ERRORTOKEN && p->tok->done == E_EOF) {
if (p->tok->level) {
raise_unclosed_parentheses_error(p);
} else {