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

Created on 2017-05-24 22:53 by lukasz.langa, last changed 2017-10-04 12:08 by eric.smith. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1800 merged lukasz.langa, 2017-05-24 22:57
PR 3409 merged python-dev, 2017-09-07 00:28
Messages (8)
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.
msg301368 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-09-05 20:37
See also issue 31140: I'm not sure if that case is covered by this issue.
msg301551 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-09-07 00:28
New changeset e7c566caf177afe43b57f0b2723e723d880368e8 by ericvsmith (Łukasz Langa) in branch 'master':
bpo-30465: Fix lineno and col_offset in fstring AST nodes (#1800)
https://github.com/python/cpython/commit/e7c566caf177afe43b57f0b2723e723d880368e8
msg301563 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-09-07 02:43
New changeset aa1afc72c1ee1f090e6302198d9a0295f1ce1c05 by ericvsmith (Miss Islington (bot)) in branch '3.6':
bpo-30465: Fix lineno and col_offset in fstring AST nodes (GH-1800) (gh-3409)
https://github.com/python/cpython/commit/aa1afc72c1ee1f090e6302198d9a0295f1ce1c05
msg303571 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2017-10-02 23:58
Is there more to do on this issue or can it be closed now?
msg303680 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-10-04 12:08
I think it's fixed. Closing.
History
Date User Action Args
2017-10-04 12:08:59eric.smithsetstatus: open -> closed
resolution: fixed
messages: + msg303680

stage: patch review -> resolved
2017-10-02 23:58:59ned.deilysetnosy: + ned.deily
messages: + msg303571
2017-09-07 02:43:06eric.smithsetmessages: + msg301563
2017-09-07 00:28:08python-devsetpull_requests: + pull_request3410
2017-09-07 00:28:00eric.smithsetmessages: + msg301551
2017-09-05 20:37:20eric.smithsetmessages: + msg301368
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