This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add line and column information for keywords in the AST
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, pablogsal
Priority: normal Keywords: patch

Created on 2020-04-01 20:49 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19283 merged pablogsal, 2020-04-01 20:50
PR 19348 merged pablogsal, 2020-04-03 19:40
Messages (4)
msg365509 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-04-01 20:49
When inspecting keyword parameters in a function call, the keyword is stored as a string and not as a AST node:

>>> import ast
>>> r = "f(a,   xxxxxxxxxxa  =  34, y=23)"
>>> node = ast.parse(r)
>>> ll = node.body[0].value.keywords[0].arg
>>> node.body[0].value.keywords[0].arg

this makes impossible to locate the keyword in the code using the AST as it lacks AST attributes (lineno, col_offset, end_lineno, end_col_offset).

On the other hand, this does not happen with args, that has the meta-information:

>>> node.body[0].value.args[0].id
>>> dir(node.body[0].value.args[0])

So one can locate the arg string using:

>>> r[arg.col_offset:arg.end_col_offset]

For this reason, we should add the same information to keyword nodes.
msg365510 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-04-01 20:56
I am preparing more PRs for other nodes that are missing the meta-information as well but will open them in a separate issue.
msg365531 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-04-01 23:47
New changeset 168660b547d5f683c5d3c60447cfa8c6d620efc3 by Pablo Galindo in branch 'master':
bpo-40141: Add line and column information to ast.keyword nodes (GH-19283)
msg365720 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-04-03 20:02
New changeset 40cf35c5b070b3f33aae58a996fea0e8291a8616 by Pablo Galindo in branch 'master':
bpo-40141: Include the value in the column position for keyword AST nodes (GH-19348)
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84322
2020-04-03 20:02:33pablogsalsetmessages: + msg365720
2020-04-03 19:40:31pablogsalsetpull_requests: + pull_request18711
2020-04-02 00:06:26pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-04-01 23:47:58pablogsalsetmessages: + msg365531
2020-04-01 22:38:13BTaskayasetnosy: + BTaskaya
2020-04-01 20:56:19pablogsalsetmessages: + msg365510
2020-04-01 20:50:02pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request18640
2020-04-01 20:49:16pablogsalcreate