classification
Title: Attribute node in a decorator has wrong end_col_offset
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: flherne, gvanrossum, lys.nikolaou, miss-islington, pablogsal
Priority: normal Keywords: patch

Created on 2020-02-07 14:44 by lys.nikolaou, last changed 2020-07-02 00:19 by flherne. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18405 merged lys.nikolaou, 2020-02-07 14:57
PR 18408 merged lys.nikolaou, 2020-02-08 00:04
Messages (5)
msg361595 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2020-02-07 14:44
There is a problem with the end_col_offset of nested Attribute nodes in decorators. For example, parsing

@a.b.c
def f(): pass

produces the following AST tree (part):

decorator_list=[
    Attribute(
        value=Attribute(
            value=Name(
                id="a",
                ctx=Load(),
                lineno=1,
                col_offset=1,
                end_lineno=1,
                end_col_offset=2,
            ),
            attr="b",
            ctx=Load(),
            lineno=1,
            col_offset=1,
            end_lineno=1,
            *end_col_offset=6*,
        ),
        attr="c",
        ctx=Load(),
        lineno=1,
        col_offset=1,
        end_lineno=1,
        end_col_offset=6,
    )
],

Note that the Attribute node with attr="b" has end_col_offset=6, while it should actually be 4.
msg361614 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-02-07 23:36
New changeset d2e1098641f98594702ef29049c3c4a3f394786f by Lysandros Nikolaou in branch 'master':
bpo-39579: Fix Attribute end_col_offset to point at the current node (GH-18405)
https://github.com/python/cpython/commit/d2e1098641f98594702ef29049c3c4a3f394786f
msg361617 - (view) Author: miss-islington (miss-islington) Date: 2020-02-08 00:21
New changeset 8b9cebce09cb6919fdb97d8e608288a503681d13 by Lysandros Nikolaou in branch '3.8':
[3.8] bpo-39579: Fix Attribute end_col_offset to point at the current node (GH-18405) (GH-18408)
https://github.com/python/cpython/commit/8b9cebce09cb6919fdb97d8e608288a503681d13
msg372796 - (view) Author: Francis Herne (flherne) Date: 2020-07-01 22:27
Note: this change causes a regression in kdev-python because our code was based on (and worked around) the long-standing previous behaviour; it produces broken results given the 'fixed' offset.

I shall have to write a patch with a version-check before our next stable release.

While the new behaviour is more logical, I'm not convinced that deliberate API breakage in a stable release - for something that's not a recent regression - was a good idea.
msg372799 - (view) Author: Francis Herne (flherne) Date: 2020-07-02 00:19
Sorry, on further inspection it was the other AST range change https://bugs.python.org/issue39474 , not this one.
History
Date User Action Args
2020-07-02 00:19:06flhernesetmessages: + msg372799
2020-07-01 22:27:37flhernesetnosy: + flherne
messages: + msg372796
2020-02-08 00:22:17gvanrossumsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-02-08 00:21:47miss-islingtonsetnosy: + miss-islington
messages: + msg361617
2020-02-08 00:04:54lys.nikolaousetpull_requests: + pull_request17783
2020-02-07 23:36:35gvanrossumsetmessages: + msg361614
2020-02-07 14:57:54lys.nikolaousetkeywords: + patch
stage: patch review
pull_requests: + pull_request17781
2020-02-07 14:44:54lys.nikolaoucreate