Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute node in a decorator has wrong end_col_offset #83760

Closed
lysnikolaou opened this issue Feb 7, 2020 · 5 comments
Closed

Attribute node in a decorator has wrong end_col_offset #83760

lysnikolaou opened this issue Feb 7, 2020 · 5 comments
Labels
3.8 (EOL) end of life 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@lysnikolaou
Copy link
Contributor

BPO 39579
Nosy @gvanrossum, @lysnikolaou, @pablogsal, @miss-islington
PRs
  • bpo-39579: Change Attribute end_col_offset to point at the current node #18405
  • [3.8] bpo-39579: Fix Attribute end_col_offset to point at the current node (GH-18405) #18408
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-02-08.00:22:17.066>
    created_at = <Date 2020-02-07.14:44:54.322>
    labels = ['interpreter-core', '3.8', '3.9']
    title = 'Attribute node in a decorator has wrong end_col_offset'
    updated_at = <Date 2020-07-02.00:19:06.909>
    user = 'https://github.com/lysnikolaou'

    bugs.python.org fields:

    activity = <Date 2020-07-02.00:19:06.909>
    actor = 'flherne'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-02-08.00:22:17.066>
    closer = 'gvanrossum'
    components = ['Interpreter Core']
    creation = <Date 2020-02-07.14:44:54.322>
    creator = 'lys.nikolaou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39579
    keywords = ['patch']
    message_count = 5.0
    messages = ['361595', '361614', '361617', '372796', '372799']
    nosy_count = 5.0
    nosy_names = ['gvanrossum', 'lys.nikolaou', 'pablogsal', 'miss-islington', 'flherne']
    pr_nums = ['18405', '18408']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39579'
    versions = ['Python 3.8', 'Python 3.9']

    @lysnikolaou
    Copy link
    Contributor Author

    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.

    @lysnikolaou lysnikolaou added 3.8 (EOL) end of life 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Feb 7, 2020
    @gvanrossum
    Copy link
    Member

    New changeset d2e1098 by Lysandros Nikolaou in branch 'master':
    bpo-39579: Fix Attribute end_col_offset to point at the current node (GH-18405)
    d2e1098

    @miss-islington
    Copy link
    Contributor

    New changeset 8b9cebc 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)
    8b9cebc

    @flherne
    Copy link
    Mannequin

    flherne mannequin commented Jul 1, 2020

    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.

    @flherne
    Copy link
    Mannequin

    flherne mannequin commented Jul 2, 2020

    Sorry, on further inspection it was the other AST range change https://bugs.python.org/issue39474 , not this one.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants