summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorMatthieu Dartiailh <marul@laposte.net>2022-04-05 13:47:13 (GMT)
committerGitHub <noreply@github.com>2022-04-05 13:47:13 (GMT)
commitaa0f056a00c4bcaef83d729e042359ddae903382 (patch)
tree45b026af73776c5f38423e44b989df335f52f405 /Parser
parentf1606a5ba50bdc4e7d335d62297b4b4043a25e6e (diff)
downloadcpython-aa0f056a00c4bcaef83d729e042359ddae903382.zip
cpython-aa0f056a00c4bcaef83d729e042359ddae903382.tar.gz
cpython-aa0f056a00c4bcaef83d729e042359ddae903382.tar.bz2
bpo-47212: Improve error messages for un-parenthesized generator expressions (GH-32302)
Diffstat (limited to 'Parser')
-rw-r--r--Parser/action_helpers.c2
-rw-r--r--Parser/parser.c6
-rw-r--r--Parser/pegen.h1
3 files changed, 5 insertions, 4 deletions
diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c
index e5d7b66..d1be679 100644
--- a/Parser/action_helpers.c
+++ b/Parser/action_helpers.c
@@ -1145,7 +1145,7 @@ _PyPegen_get_expr_name(expr_ty e)
}
}
-static inline expr_ty
+expr_ty
_PyPegen_get_last_comprehension_item(comprehension_ty comprehension) {
if (comprehension->ifs == NULL || asdl_seq_LEN(comprehension->ifs) == 0) {
return comprehension->iter;
diff --git a/Parser/parser.c b/Parser/parser.c
index 40c5d62..adc8d50 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -18968,7 +18968,7 @@ invalid_arguments_rule(Parser *p)
)
{
D(fprintf(stderr, "%*c+ invalid_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]"));
- _res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , PyPegen_last_item ( b , comprehension_ty ) -> target , "Generator expression must be parenthesized" );
+ _res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , _PyPegen_get_last_comprehension_item ( PyPegen_last_item ( b , comprehension_ty ) ) , "Generator expression must be parenthesized" );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;
@@ -19061,7 +19061,7 @@ invalid_arguments_rule(Parser *p)
)
{
D(fprintf(stderr, "%*c+ invalid_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ',' expression for_if_clauses"));
- _res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , asdl_seq_GET ( b , b -> size - 1 ) -> target , "Generator expression must be parenthesized" );
+ _res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , _PyPegen_get_last_comprehension_item ( PyPegen_last_item ( b , comprehension_ty ) ) , "Generator expression must be parenthesized" );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;
@@ -22190,7 +22190,7 @@ invalid_except_stmt_indent_rule(Parser *p)
)
{
D(fprintf(stderr, "%*c+ invalid_except_stmt_indent[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'except' ':' NEWLINE !INDENT"));
- _res = RAISE_SYNTAX_ERROR ( "expected an indented block after except statement on line %d" , a -> lineno );
+ _res = RAISE_INDENTATION_ERROR ( "expected an indented block after 'except' statement on line %d" , a -> lineno );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;
diff --git a/Parser/pegen.h b/Parser/pegen.h
index 77d5ca8..fe0c327 100644
--- a/Parser/pegen.h
+++ b/Parser/pegen.h
@@ -324,6 +324,7 @@ int _PyPegen_check_barry_as_flufl(Parser *, Token *);
int _PyPegen_check_legacy_stmt(Parser *p, expr_ty t);
mod_ty _PyPegen_make_module(Parser *, asdl_stmt_seq *);
void *_PyPegen_arguments_parsing_error(Parser *, expr_ty);
+expr_ty _PyPegen_get_last_comprehension_item(comprehension_ty comprehension);
void *_PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args, asdl_comprehension_seq *comprehensions);
// Parser API