8000 bpo-40141: Add line and column information to ast.keyword nodes (GH-1… · python/cpython@168660b · GitHub
[go: up one dir, main page]

Skip to content

Commit 168660b

Browse files
authored
bpo-40141: Add line and column information to ast.keyword nodes (GH-19283)
1 parent 65a796e commit 168660b

File tree

6 files changed

+117
-8
lines changed

6 files changed

+117
-8
lines changed

Include/Python-ast.h

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ def main():
20062006
('Expression', ('GeneratorExp', (1, 0, 1, 22), ('Tuple', (1, 1, 1, 6), [('Name', (1, 2, 1, 3), 'a', ('Load',)), ('Name', (1, 4, 1, 5), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11, 1, 16), [('Name', (1, 12, 1, 13), 'a', ('Store',)), ('Name', (1, 14, 1, 15), 'b', ('Store',))], ('Store',)), ('Name', (1, 20, 1, 21), 'c', ('Load',)), [], 0)])),
20072007
('Expression', ('GeneratorExp', (1, 0, 1, 22), ('Tuple', (1, 1, 1, 6), [('Name', (1, 2, 1, 3), 'a', ('Load',)), ('Name', (1, 4, 1, 5), 'b', ('Load',))], ('Load',)), [('comprehension', ('List', (1, 11, 1, 16), [('Name', (1, 12, 1, 13), 'a', ('Store',)), ('Name', (1, 14, 1, 15), 'b', ('Store',))], ('Store',)), ('Name', (1, 20, 1, 21), 'c', ('Load',)), [], 0)])),
20082008
('Expression', ('Compare', (1, 0, 1, 9), ('Constant', (1, 0, 1, 1), 1, None), [('Lt',), ('Lt',)], [('Constant', (1, 4, 1, 5), 2, None), ('Constant', (1, 8, 1, 9), 3, None)])),
2009-
('Expression', ('Call', (1, 0, 1, 17), ('Name', (1, 0, 1, 1), 'f', ('Load',)), [('Constant', (1, 2, 1, 3), 1, None), ('Constant', (1, 4, 1, 5), 2, None), ('Starred', (1, 10, 1, 12), ('Name', (1, 11, 1, 12), 'd', ('Load',)), ('Load',))], [('keyword', 'c', ('Constant', (1, 8, 1, 9), 3, None)), ('keyword', None, ('Name', (1, 15, 1, 16), 'e', ('Load',)))])),
2009+
('Expression', ('Call', (1, 0, 1, 17), ('Name', (1, 0, 1, 1), 'f', ('Load',)), [('Constant', (1, 2, 1, 3), 1, None), ('Constant', (1, 4, 1, 5), 2, None), ('Starred', (1, 10, 1, 12), ('Name', (1, 11, 1, 12), 'd', ('Load',)), ('Load',))], [('keyword', (1, 6, 1, 7), 'c', ('Constant', (1, 8, 1, 9), 3, None)), ('keyword', (1, 13, 1, 16), None, ('Name', (1, 15, 1, 16), 'e', ('Load',)))])),
20102010
('Expression', ('Call', (1, 0, 1, 10), ('Name', (1, 0, 1, 1), 'f', ('Load',)), [('Starred', (1, 2, 1, 9), ('List', (1, 3, 1, 9), [('Constant', (1, 4, 1, 5), 0, None), ('Constant', (1, 7, 1, 8), 1, None)], ('Load',)), ('Load',))], [])),
20112011
('Expression', ('Call', (1, 0, 1, 15), ('Name', (1, 0, 1, 1), 'f', ('Load',)), [('GeneratorExp', (1, 1, 1, 15), ('Name', (1, 2, 1, 3), 'a', ('Load',)), [('comprehension', ('Name', (1, 8, 1, 9), 'a', ('Store',)), ('Name', (1, 13, 1, 14), 'b', ('Load',)), [], 0)])], [])),
20122012
('Expression', ('Constant', (1, 0, 1, 2), 10, None)),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add column and line information to ``ast.keyword`` nodes. Patch by Pablo
2+
Galindo.

Parser/Python.asdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module Python
114114

115115
-- keyword arguments supplied to call (NULL identifier for **kwargs)
116116
keyword = (identifier? arg, expr value)
117+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
117118

118119
-- import name with optional 'as' alias.
119120
alias = (identifier name, identifier? asname)

Python/Python-ast.c

Lines changed: 100 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/ast.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,7 +3013,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func,
30133013
e = ast_for_expr(c, CHILD(ch, 1));
30143014
if (!e)
30153015
return NULL;
3016-
kw = keyword(NULL, e, c->c_arena);
3016+
kw = keyword(NULL, e, chch->n_lineno, chch->n_col_offset,
3017+
e->end_lineno, e->end_col_offset, c->c_arena);
30173018
asdl_seq_SET(keywords, nkeywords++, kw);
30183019
ndoublestars++;
30193020
}
@@ -3103,7 +3104,9 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func,
31033104
e = ast_for_expr(c, CHILD(ch, 2));
31043105
if (!e)
31053106
return NULL;
3106-
kw = keyword(key, e, c->c_arena);
3107+
kw = keyword(key, e, chch->n_lineno, chch->n_col_offset,
3108+
chch->n_end_lineno, chch->n_end_col_offset, c->c_arena);
3109+
31073110
if (!kw)
31083111
return NULL;
31093112
asdl_seq_SET(keywords, nkeywords++, kw);

0 commit comments

Comments
 (0)
0