classification
Title: col_offset for AsyncFunctionDef AST nodes is wrong
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jelle Zijlstra, benjamin.peterson, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-01-08 11:29 by Jelle Zijlstra, last changed 2019-03-04 17:18 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
issue29205.patch Jelle Zijlstra, 2017-01-08 14:03 patch + tests review
Pull Requests
URL Status Linked Edit
PR 4175 merged guoci, 2017-10-30 16:38
Messages (3)
msg284978 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2017-01-08 11:29
The col_offset attribute for ast.AsyncFunctionDef objects points to the "def" keyword, not to the "async" keyword that actually starts the node.

Test case:

In [18]: code = 'async def f(): pass'

In [19]: tree = ast.parse(code)

In [20]: tree.body[0]
Out[20]: <_ast.AsyncFunctionDef at 0x7f5cb6a58f60>

In [21]: tree.body[0].col_offset
Out[21]: 6
msg284981 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2017-01-08 11:35
The col_offset is actually correct when there is a decorator:

In [26]: code = '@decorator\nasync def f(): pass'

In [27]: tree = ast.parse(code)

In [28]: tree.body[0].col_offset
Out[28]: 0

The same issue appears with async for and async with:

In [31]: code = '@decorator\nasync def f():\n    async for x in y: pass'

In [32]: tree = ast.parse(code)

In [34]: tree.body[0].body[0]
Out[34]: <_ast.AsyncFor at 0x7f5cb6a77198>

In [35]: tree.body[0].body[0].col_offset
Out[35]: 10
msg330186 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-11-21 08:50
Is this issue fixed? Are backports needed?

I can't reproduce the issue on master and 3.7, but can reproduce it on 3.6.
History
Date User Action Args
2019-03-04 17:18:12serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-11-21 08:50:33serhiy.storchakasetnosy: + serhiy.storchaka, benjamin.peterson

messages: + msg330186
versions: - Python 3.5, Python 3.7
2017-10-30 16:38:34guocisetstage: patch review
pull_requests: + pull_request4144
2017-01-08 14:03:48Jelle Zijlstrasetkeywords: + patch
files: + issue29205.patch
2017-01-08 11:35:30Jelle Zijlstrasetmessages: + msg284981
2017-01-08 11:29:20Jelle Zijlstracreate