8000 [3.8] bpo-39080: Starred Expression's column offset fix when inside a… · python/cpython@b1f2044 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1f2044

Browse files
pablogsalmiss-islington
authored andcommitted
[3.8] bpo-39080: Starred Expression's column offset fix when inside a CALL (GH-17645) (GH-17649)
… Co-Authored-By: Pablo Galindo <Pablogsal@gmail.com> (cherry picked from commit 50d4f12) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> https://bugs.python.org/issue39080
1 parent bf3aa10 commit b1f2044

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
@@ -815,6 +817,12 @@ def test_elif_stmt_start_position_with_else(self):
815817
self.assertEqual(elif_stmt.lineno, 3)
816818
self.assertEqual(elif_stmt.col_offset, 0)
817819

820+
def test_starred_expr_end_position_within_call(self):
821+
node = ast.parse('f(*[0, 1])')
822+
starred_expr = node.body[0].value.args[0]
823+
self.assertEqual(starred_expr.end_lineno, 1)
824+
self.assertEqual(starred_expr.end_col_offset, 9)
825+
818826
def test_literal_eval(self):
819827
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
820828
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
@@ -1868,6 +1876,7 @@ def main():
18681876
('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)])),
18691877
('Expression', ('Compare', (1, 0), ('Constant', (1, 0), 1, None), [('Lt',), ('Lt',)], [('Constant', (1, 4), 2, None), ('Constant', (1, 8), 3, None)])),
18701878
('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',)))])),
1879+
('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',))], [])),
18711880
('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)])], [])),
18721881
('Expression', ('Constant', (1, 0), 10, None)),
18731882
('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)
0