classification
Title: FormattedValue expressions have wrong lineno and col_offset information
Type: behavior Stage: patch review
Components: Versions: Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: lukasz.langa Nosy List: eric.smith, lukasz.langa, rhettinger, serhiy.storchaka
Priority: normal Keywords: 3.6regression

Created on 2017-05-24 22:53 by lukasz.langa, last changed 2017-06-15 17:14 by serhiy.storchaka.

Pull Requests
URL Status Linked Edit
PR 1800 open lukasz.langa, 2017-05-24 22:57
Messages (3)
msg294408 - (view) Author: Ɓukasz Langa (lukasz.langa) * (Python committer) Date: 2017-05-24 22:53
f-strings are computed in a separate compiler step. This makes their lineno and col_offset information wrong. This is problematic for flake8 which reports problems inside f-strings on the wrong line (typically the first one).

Attached patch fixes the issue.
msg294423 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-05-25 01:34
Thanks for adding so many tests.
msg294866 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-31 18:58
I have concerns about following cases.

* f-string containing multiple equivalent subexpressions:

f'{x} {x}'

or

f'''
{x}
{x}
'''

* f-string containing escaped newlines:

f'''\
\
{x}\
\
'''

The tests look slightly verbose and fragile to me. If once the parser will produce more efficient tree (see issue26415), the tests may fail. Needed more tests (for cases mentioned above), and adding them will add more verbose code. Maybe just find the child (or several children) of specific type and check lineno and col_offset only for it and few its children? If this will make the tests simpler. But if tests can't be made simpler, we should live with this.
History
Date User Action Args
2017-06-15 17:14:38serhiy.storchakasetmessages: - msg296115
2017-06-15 17:14:26serhiy.storchakasetmessages: - msg296114
2017-06-15 17:01:02serhiy.storchakasetmessages: + msg296115
2017-06-15 16:58:43serhiy.storchakasetmessages: + msg296114
2017-05-31 18:58:39serhiy.storchakasetnosy: + eric.smith, serhiy.storchaka
messages: + msg294866
2017-05-25 01:34:16rhettingersetnosy: + rhettinger
messages: + msg294423
2017-05-24 22:57:05lukasz.langasetpull_requests: + pull_request1883
2017-05-24 22:53:37lukasz.langacreate