Skip to content

FormattedValue expressions have wrong lineno and col_offset information #74650

Closed

Description

@ambv
BPO 30465
Nosy @rhettinger, @vstinner, @ericvsmith, @ned-deily, @ambv, @serhiy-storchaka, @asottile
PRs
  • bpo-30465: Fix lineno and col_offset in fstring AST nodes #1800
  • [3.6] bpo-30465: Fix lineno and col_offset in fstring AST nodes (GH-1800) #3409
  • bpo-30465: Fix C downcast warning on Windows in ast.c #6593
  • [3.7] bpo-9566: Fix compiler warnings on Windows #12920
  • bpo-16806: Fix lineno and col_offset for multi-line string tokens. #10021
  • 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 = 'https://github.com/ambv'
    closed_at = <Date 2017-10-04.12:08:59.860>
    created_at = <Date 2017-05-24.22:53:37.508>
    labels = ['type-bug', '3.7']
    title = 'FormattedValue expressions have wrong lineno and col_offset information'
    updated_at = <Date 2020-04-01.23:22:36.159>
    user = 'https://github.com/ambv'

    bugs.python.org fields:

    activity = <Date 2020-04-01.23:22:36.159>
    actor = 'Anthony Sottile'
    assignee = 'lukasz.langa'
    closed = True
    closed_date = <Date 2017-10-04.12:08:59.860>
    closer = 'eric.smith'
    components = []
    creation = <Date 2017-05-24.22:53:37.508>
    creator = 'lukasz.langa'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30465
    keywords = ['3.6regression']
    message_count = 10.0
    messages = ['294408', '294423', '294866', '301368', '301551', '301563', '303571', '303680', '315971', '340699']
    nosy_count = 7.0
    nosy_names = ['rhettinger', 'vstinner', 'eric.smith', 'ned.deily', 'lukasz.langa', 'serhiy.storchaka', 'Anthony Sottile']
    pr_nums = ['1800', '3409', '6593', '12920', '10021']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30465'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. ambv commented on May 24, 2017

      @ambv
      ContributorAuthor

      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.

    2. self-assigned this
      on May 24, 2017
    3. added
      type-bugAn unexpected behavior, bug, or error
      on May 24, 2017
    4. rhettinger commented on May 25, 2017

      @rhettinger
      Contributor

      Thanks for adding so many tests.

    5. serhiy-storchaka commented on May 31, 2017

      @serhiy-storchaka
      Member

      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 bpo-26415), 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.

    6. ericvsmith commented on Sep 5, 2017

      @ericvsmith
      Member

      See also bpo-31140: I'm not sure if that case is covered by this issue.

    7. ericvsmith commented on Sep 7, 2017

      @ericvsmith
      Member

      New changeset e7c566c by ericvsmith (Łukasz Langa) in branch 'master':
      bpo-30465: Fix lineno and col_offset in fstring AST nodes (bpo-1800)
      e7c566c

    8. ericvsmith commented on Sep 7, 2017

      @ericvsmith
      Member

      New changeset aa1afc7 by ericvsmith (Miss Islington (bot)) in branch '3.6':
      bpo-30465: Fix lineno and col_offset in fstring AST nodes (GH-1800) (gh-3409)
      aa1afc7

    9. ned-deily commented on Oct 2, 2017

      @ned-deily
      Member

      Is there more to do on this issue or can it be closed now?

    10. ericvsmith commented on Oct 4, 2017

      @ericvsmith
      Member

      I think it's fixed. Closing.

    11. ambv commented on Apr 30, 2018

      @ambv
      ContributorAuthor

      New changeset fb7e799 by Łukasz Langa (Victor Stinner) in branch 'master':
      bpo-30465: Fix C downcast warning on Windows in ast.c (bpo-6593)
      fb7e799

    12. vstinner commented on Apr 23, 2019

      @vstinner
      Member

      New changeset 8a9a6b4 by Victor Stinner in branch '3.7':
      [3.7] bpo-9566: Fix compiler warnings on Windows (GH-12920)
      8a9a6b4

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

    Labels

    3.7 (EOL)end of lifetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions