Skip to content

Commit 50d4f12

Browse files
bpo-39080: Starred Expression's column offset fix when inside a CALL (GH-17645)
Co-Authored-By: Pablo Galindo <[email protected]>
1 parent a9d0a6a commit 50d4f12

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/test/test_ast.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def to_tuple(t):
209209
"1 < 2 < 3",
210210
# Call
211211
"f(1,2,c=3,*d,**e)",
212+
# Call with multi-character starred
213+
"f(*[0, 1])",
212214
# Call with a generator argument
213215
"f(a for a in b)",
214216
# Num
@@ -877,6 +879,12 @@ def test_elif_stmt_start_position_with_else(self):
877879
self.assertEqual(elif_stmt.lineno, 3)
878880
self.assertEqual(elif_stmt.col_offset, 0)
879881

882+
def test_starred_expr_end_position_within_call(self):
883+
node = ast.parse('f(*[0, 1])')
884+
starred_expr = node.body[0].value.args[0]
885+
self.assertEqual(starred_expr.end_lineno, 1)
886+
self.assertEqual(starred_expr.end_col_offset, 9)
887+
880888
def test_literal_eval(self):
881889
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
882890
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
@@ -1930,6 +1938,7 @@ def main():
19301938
('Expression', ('GeneratorExp', (1, 0), ('Tuple', (1, 1), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('List', (1, 11), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [], 0)])),
19311939
('Expression', ('Compare', (1, 0), ('Constant', (1, 0), 1, None), [('Lt',), ('Lt',)], [('Constant', (1, 4), 2, None), ('Constant', (1, 8), 3, None)])),
19321940
('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Constant', (1, 2), 1, None), ('Constant', (1, 4), 2, None), ('Starred', (1, 10), ('Name', (1, 11), 'd', ('Load',)), ('Load',))], [('keyword', 'c', ('Constant', (1, 8), 3, None)), ('keyword', None, ('Name', (1, 15), 'e', ('Load',)))])),
1941+
('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Starred', (1, 2), ('List', (1, 3), [('Constant', (1, 4), 0, None), ('Constant', (1, 7), 1, None)], ('Load',)), ('Load',))], [])),
19331942
('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('GeneratorExp', (1, 1), ('Name', (1, 2), 'a', ('Load',)), [('comprehension', ('Name', (1, 8), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Load',)), [], 0)])], [])),
19341943
('Expression', ('Constant', (1, 0), 10, None)),
19351944
('Expression', ('Constant', (1, 0), 'string', None)),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the value of *end_col_offset* for Starred Expression AST nodes when they are among the elements in the *args* attribute of Call AST nodes.

Python/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3126,7 +3126,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func,
31263126
return NULL;
31273127
starred = Starred(e, Load, LINENO(chch),
31283128
chch->n_col_offset,
3129-
chch->n_end_lineno, chch->n_end_col_offset,
3129+
e->end_lineno, e->end_col_offset,
31303130
c->c_arena);
31313131
if (!starred)
31323132
return NULL;

0 commit comments

Comments
 (0)