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

Add position metadata to alias AST type #87964

Closed
msuozzo mannequin opened this issue Apr 9, 2021 · 9 comments
Closed

Add position metadata to alias AST type #87964

msuozzo mannequin opened this issue Apr 9, 2021 · 9 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@msuozzo
Copy link
Mannequin

msuozzo mannequin commented Apr 9, 2021

BPO 43798
Nosy @gvanrossum, @blueyed, @The-Compiler, @lysnikolaou, @pablogsal, @isidentical, @hauntsaninja, @msuozzo
PRs
  • bpo-43798: Add source location attributes to alias. #25324
  • 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 2021-04-10.20:57:20.714>
    created_at = <Date 2021-04-09.20:28:56.470>
    labels = ['interpreter-core', 'type-feature', '3.10']
    title = 'Add position metadata to alias AST type'
    updated_at = <Date 2021-04-14.15:03:48.078>
    user = 'https://github.com/msuozzo'

    bugs.python.org fields:

    activity = <Date 2021-04-14.15:03:48.078>
    actor = 'The Compiler'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-10.20:57:20.714>
    closer = 'lys.nikolaou'
    components = ['Interpreter Core']
    creation = <Date 2021-04-09.20:28:56.470>
    creator = 'matthew.suozzo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43798
    keywords = ['patch']
    message_count = 9.0
    messages = ['390663', '390673', '390675', '390677', '390740', '390800', '390807', '390901', '390902']
    nosy_count = 8.0
    nosy_names = ['gvanrossum', 'blueyed', 'The Compiler', 'lys.nikolaou', 'pablogsal', 'BTaskaya', 'hauntsaninja', 'matthew.suozzo']
    pr_nums = ['25324']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue43798'
    versions = ['Python 3.10']

    @msuozzo
    Copy link
    Mannequin Author

    msuozzo mannequin commented Apr 9, 2021

    Given the increasing use of long from typing import foo, bar, ... import sequences, it's becoming more desirable to address individual components of the import node. Unfortunately, the ast.alias node doesn't contain source location metadata (e.g. lineno, col_offset).

    This metadata would be comparatively easy to add, backwards compatible, and would enable more precise diagnostics e.g. lints.

    @msuozzo msuozzo mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Apr 9, 2021
    @msuozzo
    Copy link
    Mannequin Author

    msuozzo mannequin commented Apr 9, 2021

    Ah and one other question: Is this normally the sort of thing that would get backported? It should be very straightforward to do so, at least for 3.9 given the support for the new parser.

    @msuozzo msuozzo mannequin removed 3.7 (EOL) end of life 3.8 only security fixes labels Apr 9, 2021
    @lysnikolaou
    Copy link
    Contributor

    I'm okay with this, unless someone has any input on why the alias node should not have line/column info (and did not have it in the first place).

    @pablogsal
    Copy link
    Member

    Ah and one other question: Is this normally the sort of thing that would get backported? It should be very straightforward to do so, at least for 3.9 given the support for the new parser.

    Unfortunately no, is technically a new feature.

    @lysnikolaou
    Copy link
    Contributor

    New changeset 75a06f0 by Matthew Suozzo in branch 'master':
    bpo-43798: Add source location attributes to alias (GH-25324)
    75a06f0

    @hauntsaninja
    Copy link
    Contributor

    FYI, probably unavoidable, but this appears to have broken pytest pytest-dev/pytest#8539

    @pablogsal
    Copy link
    Member

    FYI, probably unavoidable, but this appears to have broken pytest pytest-dev/pytest#8539

    What's the problem? alias objects *have* lineno argument:

    >>> print(ast.dump(ast.parse("from x import y"), include_attributes=True, indent=4))
    Module(
        body=[
            ImportFrom(
                module='x',
                names=[
                    alias(
                        name='y',
                        lineno=1,
                        col_offset=14,
                        end_lineno=1,
                        end_col_offset=15)],
                level=0,
                lineno=1,
                col_offset=0,
                end_lineno=1,
                end_col_offset=15)],
        type_ignores=[])

    @blueyed
    Copy link
    Mannequin

    blueyed mannequin commented Apr 12, 2021

    @pablo: the problem (referenced in the pytest issue) is that ast.alias has new required arguments now (see also the adjusted test in
    75a06f0#diff-3f516b60719dd445d33225e4f316b36e85c9c51a843a0147349d11a005c55937R1060-R1061). That's expected/wanted though (assuming that it should not have "defaults" for B/C), and there's a patch for the issue at pytest-dev/pytest#8540.

    @blueyed blueyed mannequin removed 3.9 only security fixes labels Apr 12, 2021
    @pablogsal
    Copy link
    Member

    Ah, it was not clear from the issue that pytest was constructing nodes by hand. It makes sense now. Thanks!

    @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.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants