diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-09-26 05:44:43 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-09-26 05:44:43 (GMT) |
commit | 58b53953f80f2b2c5a8583a04ce737acfb326def (patch) | |
tree | 749dfca8e0062cdb881d9d1b2b98e2369c05795c /Python | |
parent | 58b07a605d7f5194df2978cfc81c598730dc84d6 (diff) | |
download | cpython-58b53953f80f2b2c5a8583a04ce737acfb326def.zip cpython-58b53953f80f2b2c5a8583a04ce737acfb326def.tar.gz cpython-58b53953f80f2b2c5a8583a04ce737acfb326def.tar.bz2 |
make opening brace of container literals and comprehensions correspond to the line number and col offset of the AST node (closes #25131)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Python/ast.c b/Python/ast.c index b2f09b9..dd5187a 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2101,6 +2101,7 @@ ast_for_atom(struct compiling *c, const node *n) * (comp_for | (',' (test ':' test | '**' test))* [','])) | * ((test | '*' test) * (comp_for | (',' (test | '*' test))* [','])) ) */ + expr_ty res; ch = CHILD(n, 1); if (TYPE(ch) == RBRACE) { /* It's an empty dict. */ @@ -2112,12 +2113,12 @@ ast_for_atom(struct compiling *c, const node *n) (NCH(ch) > 1 && TYPE(CHILD(ch, 1)) == COMMA)) { /* It's a set display. */ - return ast_for_setdisplay(c, ch); + res = ast_for_setdisplay(c, ch); } else if (NCH(ch) > 1 && TYPE(CHILD(ch, 1)) == comp_for) { /* It's a set comprehension. */ - return ast_for_setcomp(c, ch); + res = ast_for_setcomp(c, ch); } else if (NCH(ch) > 3 - is_dict && TYPE(CHILD(ch, 3 - is_dict)) == comp_for) { @@ -2127,12 +2128,17 @@ ast_for_atom(struct compiling *c, const node *n) "dict comprehension"); return NULL; } - return ast_for_dictcomp(c, ch); + res = ast_for_dictcomp(c, ch); } else { /* It's a dictionary display. */ - return ast_for_dictdisplay(c, ch); + res = ast_for_dictdisplay(c, ch); } + if (res) { + res->lineno = LINENO(n); + res->col_offset = n->n_col_offset; + } + return res; } } default: |