New submission from Pablo Galindo Salgado <pablog...@gmail.com>:

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
'xxxxxxxxxxa'

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
'a'
>>> dir(node.body[0].value.args[0])


So one can locate the arg string using:

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

For this reason, we should add the same information to keyword nodes.

----------
components: Interpreter Core
messages: 365509
nosy: pablogsal
priority: normal
severity: normal
status: open
title: Add line and column information for keywords in the AST
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40141>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to