diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-18 20:32:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 20:32:01 (GMT) |
commit | 846a10fc45ef83b41d1b1b568a9ee8012f37c8c2 (patch) | |
tree | be89748501548ee29a1db86ae0e835ee185bb29f /Parser/parser.c | |
parent | d1c0e4413dd544270df1f5b8a145fd4370cb759b (diff) | |
download | cpython-846a10fc45ef83b41d1b1b568a9ee8012f37c8c2.zip cpython-846a10fc45ef83b41d1b1b568a9ee8012f37c8c2.tar.gz cpython-846a10fc45ef83b41d1b1b568a9ee8012f37c8c2.tar.bz2 |
bpo-44947: Refine the syntax error for trailing commas in import statements (GH-27814)
(cherry picked from commit b2f68b190035540872072ac1d2349e7745e85596)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser/parser.c')
-rw-r--r-- | Parser/parser.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Parser/parser.c b/Parser/parser.c index acaa7b0..e57c603 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -19607,7 +19607,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) { @@ -19618,21 +19618,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; @@ -19643,7 +19646,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: |