Skip to content

Add position metadata to alias AST type #87964

Closed

Description

@msuozzo
mannequin
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']

    Activity

    1. msuozzo commented on Apr 9, 2021

      msuozzomannequin
      MannequinAuthor

      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.

    2. msuozzo commented on Apr 9, 2021

      msuozzomannequin
      MannequinAuthor

      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.

    3. lysnikolaou commented on Apr 9, 2021

      @lysnikolaou
      Member

      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).

    4. pablogsal commented on Apr 9, 2021

      @pablogsal
      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.

    5. lysnikolaou commented on Apr 10, 2021

      @lysnikolaou
      Member

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

    6. hauntsaninja commented on Apr 11, 2021

      @hauntsaninja
      Contributor

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

    7. pablogsal commented on Apr 11, 2021

      @pablogsal
      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=[])
    8. blueyed commented on Apr 12, 2021

      blueyedmannequin
      Mannequin

      @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.

    9. pablogsal commented on Apr 12, 2021

      @pablogsal
      Member

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

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions