Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
26ae9f6d
Commit
26ae9f6d
authored
Oct 26, 2019
by
Serhiy Storchaka
Committed by
GitHub
Oct 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38535: Fix positions for AST nodes for calls without arguments in decorators. (GH-16861)
parent
cb2cf06b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
8 deletions
+12
-8
Lib/test/test_ast.py
Lib/test/test_ast.py
+6
-6
Misc/NEWS.d/next/Core and Builtins/2019-10-20-12-43-48.bpo-38535.ESMkVN.rst
...ore and Builtins/2019-10-20-12-43-48.bpo-38535.ESMkVN.rst
+2
-0
Python/ast.c
Python/ast.c
+4
-2
No files found.
Lib/test/test_ast.py
View file @
26ae9f6d
...
...
@@ -129,11 +129,11 @@ exec_tests = [
# Asynchronous comprehensions
"async def f():
\
n
[i async for b in c]"
,
# Decorated FunctionDef
"@deco1
\
n
@deco2()
\
n
def f(): pass"
,
"@deco1
\
n
@deco2()
\
n
@deco3(1)
\
n
def f(): pass"
,
# Decorated AsyncFunctionDef
"@deco1
\
n
@deco2()
\
n
async def f(): pass"
,
"@deco1
\
n
@deco2()
\
n
@deco3(1)
\
n
async def f(): pass"
,
# Decorated ClassDef
"@deco1
\
n
@deco2()
\
n
class C: pass"
,
"@deco1
\
n
@deco2()
\
n
@deco3(1)
\
n
class C: pass"
,
# Decorator with generator argument
"@deco(a for a in b)
\
n
def f(): pass"
,
# Simple assignment expression
...
...
@@ -1870,9 +1870,9 @@ exec_results = [
(
'Module'
,
[(
'Expr'
,
(
1
,
0
),
(
'Dict'
,
(
1
,
0
),
[
None
,
(
'Constant'
,
(
1
,
10
),
2
,
None
)],
[(
'Dict'
,
(
1
,
3
),
[(
'Constant'
,
(
1
,
4
),
1
,
None
)],
[(
'Constant'
,
(
1
,
6
),
2
,
None
)]),
(
'Constant'
,
(
1
,
12
),
3
,
None
)]))],
[]),
(
'Module'
,
[(
'Expr'
,
(
1
,
0
),
(
'Set'
,
(
1
,
0
),
[(
'Starred'
,
(
1
,
1
),
(
'Set'
,
(
1
,
2
),
[(
'Constant'
,
(
1
,
3
),
1
,
None
),
(
'Constant'
,
(
1
,
6
),
2
,
None
)]),
(
'Load'
,)),
(
'Constant'
,
(
1
,
10
),
3
,
None
)]))],
[]),
(
'Module'
,
[(
'AsyncFunctionDef'
,
(
1
,
0
),
'f'
,
(
'arguments'
,
[],
[],
None
,
[],
[],
None
,
[]),
[(
'Expr'
,
(
2
,
1
),
(
'ListComp'
,
(
2
,
1
),
(
'Name'
,
(
2
,
2
),
'i'
,
(
'Load'
,)),
[(
'comprehension'
,
(
'Name'
,
(
2
,
14
),
'b'
,
(
'Store'
,)),
(
'Name'
,
(
2
,
19
),
'c'
,
(
'Load'
,)),
[],
1
)]))],
[],
None
,
None
)],
[]),
(
'Module'
,
[(
'FunctionDef'
,
(
3
,
0
),
'f'
,
(
'arguments'
,
[],
[],
None
,
[],
[],
None
,
[]),
[(
'Pass'
,
(
3
,
9
))],
[(
'Name'
,
(
1
,
1
),
'deco1'
,
(
'Load'
,)),
(
'Call'
,
(
2
,
0
),
(
'Name'
,
(
2
,
1
),
'deco2'
,
(
'Load'
,)),
[
],
[])],
None
,
None
)],
[]),
(
'Module'
,
[(
'AsyncFunctionDef'
,
(
3
,
0
),
'f'
,
(
'arguments'
,
[],
[],
None
,
[],
[],
None
,
[]),
[(
'Pass'
,
(
3
,
15
))],
[(
'Name'
,
(
1
,
1
),
'deco1'
,
(
'Load'
,)),
(
'Call'
,
(
2
,
0
),
(
'Name'
,
(
2
,
1
),
'deco2'
,
(
'Load'
,)),
[
],
[])],
None
,
None
)],
[]),
(
'Module'
,
[(
'ClassDef'
,
(
3
,
0
),
'C'
,
[],
[],
[(
'Pass'
,
(
3
,
9
))],
[(
'Name'
,
(
1
,
1
),
'deco1'
,
(
'Load'
,)),
(
'Call'
,
(
2
,
0
),
(
'Name'
,
(
2
,
1
),
'deco2'
,
(
'Load'
,)),
[
],
[])])],
[]),
(
'Module'
,
[(
'FunctionDef'
,
(
4
,
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'
,)),
[(
'Constant'
,
(
3
,
7
),
1
,
None
)
],
[])],
None
,
None
)],
[]),
(
'Module'
,
[(
'AsyncFunctionDef'
,
(
4
,
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'
,)),
[(
'Constant'
,
(
3
,
7
),
1
,
None
)
],
[])],
None
,
None
)],
[]),
(
'Module'
,
[(
'ClassDef'
,
(
4
,
0
),
'C'
,
[],
[],
[(
'Pass'
,
(
4
,
9
))],
[(
'Name'
,
(
1
,
1
),
'deco1'
,
(
'Load'
,)),
(
'Call'
,
(
2
,
1
),
(
'Name'
,
(
2
,
1
),
'deco2'
,
(
'Load'
,)),
[],
[]),
(
'Call'
,
(
3
,
1
),
(
'Name'
,
(
3
,
1
),
'deco3'
,
(
'Load'
,)),
[(
'Constant'
,
(
3
,
7
),
1
,
None
)
],
[])])],
[]),
(
'Module'
,
[(
'FunctionDef'
,
(
2
,
0
),
'f'
,
(
'arguments'
,
[],
[],
None
,
[],
[],
None
,
[]),
[(
'Pass'
,
(
2
,
9
))],
[(
'Call'
,
(
1
,
1
),
(
'Name'
,
(
1
,
1
),
'deco'
,
(
'Load'
,)),
[(
'GeneratorExp'
,
(
1
,
5
),
(
'Name'
,
(
1
,
6
),
'a'
,
(
'Load'
,)),
[(
'comprehension'
,
(
'Name'
,
(
1
,
12
),
'a'
,
(
'Store'
,)),
(
'Name'
,
(
1
,
17
),
'b'
,
(
'Load'
,)),
[],
0
)])],
[])],
None
,
None
)],
[]),
(
'Module'
,
[(
'Expr'
,
(
1
,
0
),
(
'NamedExpr'
,
(
1
,
1
),
(
'Name'
,
(
1
,
1
),
'a'
,
(
'Store'
,)),
(
'Constant'
,
(
1
,
6
),
1
,
None
)))],
[]),
(
'Module'
,
[(
'FunctionDef'
,
(
1
,
0
),
'f'
,
(
'arguments'
,
[(
'arg'
,
(
1
,
6
),
'a'
,
None
,
None
)],
[],
None
,
[],
[],
None
,
[]),
[(
'Pass'
,
(
1
,
14
))],
[],
None
,
None
)],
[]),
...
...
Misc/NEWS.d/next/Core and Builtins/2019-10-20-12-43-48.bpo-38535.ESMkVN.rst
0 → 100644
View file @
26ae9f6d
Fixed line numbers and column offsets for AST nodes for calls without
arguments in decorators.
Python/ast.c
View file @
26ae9f6d
...
...
@@ -1747,8 +1747,10 @@ ast_for_decorator(struct compiling *c, const node *n)
name_expr
=
NULL
;
}
else
if
(
NCH
(
n
)
==
5
)
{
/* Call with no arguments */
d
=
Call
(
name_expr
,
NULL
,
NULL
,
LINENO
(
n
),
n
->
n_col_offset
,
n
->
n_end_lineno
,
n
->
n_end_col_offset
,
c
->
c_arena
);
d
=
Call
(
name_expr
,
NULL
,
NULL
,
name_expr
->
lineno
,
name_expr
->
col_offset
,
CHILD
(
n
,
3
)
->
n_end_lineno
,
CHILD
(
n
,
3
)
->
n_end_col_offset
,
c
->
c_arena
);
if
(
!
d
)
return
NULL
;
name_expr
=
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment