[issue42806] Incorrect offsets in new parser for f-string substitutions
Pablo Galindo Salgado
report at bugs.python.org
Sat Jan 2 19:19:23 EST 2021
Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:
Seems that I also found this weird behaviour in the old parser:
import ast
code = """\
x = (
'PERL_MM_OPT', (
f'wat'
f'INSTALL-BASE={shlex.quote(venv)} '
f'wat'
),
)
"""
elem = ast.parse(code).body[0].value.elts[1].values[1].value
print(elem)
print(code.split("\n")[elem.lineno-1][elem.col_offset:elem.end_col_offset])
In Python3.8 this prints:
<_ast.Call object at 0x7f7484393a00>
'wat'
which is wrong as the code for that call is certainly not "wat". This happens in the oldparser in 3.9:
❯ ../3.9/python -Xoldparser lel.py
<ast.Call object at 0x7f78afbc1e10>
'wat'
And something wrong happens in the current master with the new parser:
❯ ../3.9/python lel.py
<ast.Call object at 0x7f504e9a1eb0>
STALL-BASE={shlex
But with PR24067:
<ast.Call object at 0x7fec78673fa0>
shlex.quote(venv)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42806>
_______________________________________
More information about the Python-bugs-list
mailing list