8000 [3.7] bpo-38535: Fix positions for AST nodes for calls without argume… · python/cpython@91fc9cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 91fc9cf

Browse files
[3.7] bpo-38535: Fix positions for AST nodes for calls without arguments in decorators. (GH-16861). (GH-16930)
(cherry picked from commit 26ae9f6)
1 parent 5207cc0 commit 91fc9cf

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Lib/test/test_ast.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def to_tuple(t):
125125
"{*{1, 2}, 3}",
126126
# Asynchronous comprehensions
127127
"async def f():\n [i async for b in c]",
128+
# Decorated FunctionDef
129+
"@deco1\n@deco2()\n@deco3(1)\ndef f(): pass",
130+
# Decorated AsyncFunctionDef
131+
"@deco1\n@deco2()\n@deco3(1)\nasync def f(): pass",
132+
# Decorated ClassDef
133+
"@deco1\n@deco2()\n@deco3(1)\nclass C: pass",
134+
# Decorator with generator argument
135+
"@deco(a for a in b)\ndef f(): pass",
128136
]
129137

130138
# These are compiled through "single"
@@ -1255,6 +1263,10 @@ def main():
12551263
('Module', [('Expr', (1, 0), ('Dict', (1, 0), [None, ('Num', (1, 10), 2)], [('Dict', (1, 3), [('Num', (1, 4), 1)], [('Num', (1, 6), 2)]), ('Num', (1, 12), 3)]))]),
12561264
('Module', [('Expr', (1, 0), ('Set', (1, 0), [('Starred', (1, 1), ('Set', (1, 2), [('Num', (1, 3), 1), ('Num', (1, 6), 2)]), ('Load',)), ('Num', (1, 10), 3)]))]),
12571265
('Module', [('AsyncFunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, []), [('Expr', (2, 1), ('ListComp', (2, 2), ('Name', (2, 2), 'i', ('Load',)), [('comprehension', ('Name', (2, 14), 'b', ('Store',)), ('Name', (2, 19), 'c', ('Load',)), [], 1)]))], [], None)]),
1266+
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, []), [('Pass', (4, 9))], [('Name', (1, 1), 'deco1', ('Load',)), ('Call', (2, 1), ('Name', (2, 1), 'deco2', ('Load',)), [], []), ('Call', (3, 1), ('Name', (3, 1), 'deco3', ('Load',)), [('Num', (3, 7), 1)], [])], None)]),
1267+
('Module', [('AsyncFunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, []), [('Pass', (4, 15))], [('Name', (1, 1), 'deco1', ('Load',)), ('Call', (2, 1), ('Name', (2, 1), 'deco2', ('Load',)), [], []), ('Call', (3, 1), ('Name', (3, 1), 'deco3', ('Load',)), [('Num', (3, 7), 1)], [])], None)]),
1268+
('Module', [('ClassDef', (1, 0), 'C', [], [], [('Pass', (4, 9))], [('Name', (1, 1), 'deco1', ('Load',)), ('Call', (2, 1), ('Name', (2, 1), 'deco2&# 8000 39;, ('Load',)), [], []), ('Call', (3, 1), ('Name', (3, 1), 'deco3', ('Load',)), [('Num', (3, 7), 1)], [])])]),
1269+
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, []), [('Pass', (2, 9))], [('Call', (1, 1), ('Name', (1, 1), 'deco', ('Load',)), [('GeneratorExp', (1, 6), ('Name', (1, 6), 'a', ('Load',)), [('comprehension', ('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 17), 'b', ('Load',)), [], 0)])], [])], None)]),
12581270
]
12591271
single_results = [
12601272
('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed line numbers and column offsets for AST nodes for calls without
2+
arguments in decorators.

Python/ast.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,9 @@ ast_for_decorator(struct compiling *c, const node *n)
15311531
name_expr = NULL;
15321532
}
15331533
else if (NCH(n) == 5) { /* Call with no arguments */
1534-
d = Call( 616C name_expr, NULL, NULL, LINENO(n),
1535-
n->n_col_offset, c->c_arena);
1534+
d = Call(name_expr, NULL, NULL,
1535+
name_expr->lineno, name_expr->col_offset,
1536+
c->c_arena);
15361537
if (!d)
15371538
return NULL;
15381539
name_expr = NULL;

0 commit comments

Comments
 (0)
0