[Python-checkins] [3.8] bpo-39080: Starred Expression's column offset fix when inside a CALL (GH-17645) (GH-17649)
Miss Islington (bot)
webhook-mailer at python.org
Tue Dec 17 20:42:04 EST 2019
https://github.com/python/cpython/commit/b1f204471092678dd89117e608fa041a9589d14c
commit: b1f204471092678dd89117e608fa041a9589d14c
branch: 3.8
author: Pablo Galindo <Pablogsal at gmail.com>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2019-12-17T17:41:58-08:00
summary:
[3.8] bpo-39080: Starred Expression's column offset fix when inside a CALL (GH-17645) (GH-17649)
…
Co-Authored-By: Pablo Galindo <Pablogsal at gmail.com>
(cherry picked from commit 50d4f12958bf806a4e1a1021d70cfd5d448c5cba)
Co-authored-by: Lysandros Nikolaou <lisandrosnik at gmail.com>
https://bugs.python.org/issue39080
files:
A Misc/NEWS.d/next/Core and Builtins/2019-12-17-21-45-36.bpo-39080.OrxEVS.rst
M Lib/test/test_ast.py
M Python/ast.c
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index caea84f80f6a4..69ed83cd8b68b 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -209,6 +209,8 @@ def to_tuple(t):
"1 < 2 < 3",
# Call
"f(1,2,c=3,*d,**e)",
+ # Call with multi-character starred
+ "f(*[0, 1])",
# Call with a generator argument
"f(a for a in b)",
# Num
@@ -815,6 +817,12 @@ def test_elif_stmt_start_position_with_else(self):
self.assertEqual(elif_stmt.lineno, 3)
self.assertEqual(elif_stmt.col_offset, 0)
+ def test_starred_expr_end_position_within_call(self):
+ node = ast.parse('f(*[0, 1])')
+ starred_expr = node.body[0].value.args[0]
+ self.assertEqual(starred_expr.end_lineno, 1)
+ self.assertEqual(starred_expr.end_col_offset, 9)
+
def test_literal_eval(self):
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
@@ -1868,6 +1876,7 @@ def main():
('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)])),
('Expression', ('Compare', (1, 0), ('Constant', (1, 0), 1, None), [('Lt',), ('Lt',)], [('Constant', (1, 4), 2, None), ('Constant', (1, 8), 3, None)])),
('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',)))])),
+('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',))], [])),
('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)])], [])),
('Expression', ('Constant', (1, 0), 10, None)),
('Expression', ('Constant', (1, 0), 'string', None)),
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-12-17-21-45-36.bpo-39080.OrxEVS.rst b/Misc/NEWS.d/next/Core and Builtins/2019-12-17-21-45-36.bpo-39080.OrxEVS.rst
new file mode 100644
index 0000000000000..b120d496b81e0
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-12-17-21-45-36.bpo-39080.OrxEVS.rst
@@ -0,0 +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.
diff --git a/Python/ast.c b/Python/ast.c
index 7081394e5844b..e70ab519e66e1 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -3126,7 +3126,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func,
return NULL;
starred = Starred(e, Load, LINENO(chch),
chch->n_col_offset,
- chch->n_end_lineno, chch->n_end_col_offset,
+ e->end_lineno, e->end_col_offset,
c->c_arena);
if (!starred)
return NULL;
More information about the Python-checkins
mailing list