summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2021-08-18 20:09:21 (GMT)
committerGitHub <noreply@github.com>2021-08-18 20:09:21 (GMT)
commitb2f68b190035540872072ac1d2349e7745e85596 (patch)
treebd130a26b96442cbe45d4b3c397f39ad6faaf057 /Parser
parent31ee985db86c1339d00bd0d3cc1712019460670a (diff)
downloadcpython-b2f68b190035540872072ac1d2349e7745e85596.zip
cpython-b2f68b190035540872072ac1d2349e7745e85596.tar.gz
cpython-b2f68b190035540872072ac1d2349e7745e85596.tar.bz2
bpo-44947: Refine the syntax error for trailing commas in import statements (GH-27814)
Diffstat (limited to 'Parser')
-rw-r--r--Parser/parser.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Parser/parser.c b/Parser/parser.c
index 01082fa..87227b7 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -19540,7 +19540,7 @@ invalid_group_rule(Parser *p)
return _res;
}
-// invalid_import_from_targets: import_from_as_names ','
+// invalid_import_from_targets: import_from_as_names ',' NEWLINE
static void *
invalid_import_from_targets_rule(Parser *p)
{
@@ -19551,21 +19551,24 @@ invalid_import_from_targets_rule(Parser *p)
}
void * _res = NULL;
int _mark = p->mark;
- { // import_from_as_names ','
+ { // import_from_as_names ',' NEWLINE
if (p->error_indicator) {
D(p->level--);
return NULL;
}
- D(fprintf(stderr, "%*c> invalid_import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_names ','"));
+ D(fprintf(stderr, "%*c> invalid_import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_names ',' NEWLINE"));
Token * _literal;
asdl_alias_seq* import_from_as_names_var;
+ Token * newline_var;
if (
(import_from_as_names_var = import_from_as_names_rule(p)) // import_from_as_names
&&
(_literal = _PyPegen_expect_token(p, 12)) // token=','
+ &&
+ (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE'
)
{
- D(fprintf(stderr, "%*c+ invalid_import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_names ','"));
+ D(fprintf(stderr, "%*c+ invalid_import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_names ',' NEWLINE"));
_res = RAISE_SYNTAX_ERROR ( "trailing comma not allowed without surrounding parentheses" );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
@@ -19576,7 +19579,7 @@ invalid_import_from_targets_rule(Parser *p)
}
p->mark = _mark;
D(fprintf(stderr, "%*c%s invalid_import_from_targets[%d-%d]: %s failed!\n", p->level, ' ',
- p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_names ','"));
+ p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_names ',' NEWLINE"));
}
_res = NULL;
done: