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

Highlight invalid ranges in SyntaxErrors #88080

Closed
pablogsal opened this issue Apr 22, 2021 · 10 comments
Closed

Highlight invalid ranges in SyntaxErrors #88080

pablogsal opened this issue Apr 22, 2021 · 10 comments
Labels
3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@pablogsal
Copy link
Member

BPO 43914
Nosy @terryjreedy, @aroberge, @merwok, @ambv, @lysnikolaou, @pablogsal, @miss-islington
PRs
  • bpo-43914: Highlight invalid ranges in SyntaxErrors #25525
  • bpo-43914: Add new SyntaxError attributes to What's New #25582
  • bpo-43914: Whats New 310: add new SyntaxError attributes #28558
  • [3.10] bpo-43914: What's New 3.10: add new SyntaxError attributes (GH-28558) #28562
  • bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls #28576
  • [3.10] bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576) #28582
  • 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-09-25.09:33:00.119>
    created_at = <Date 2021-04-22.18:08:10.767>
    labels = ['interpreter-core', '3.10', '3.11']
    title = 'Highlight invalid ranges in SyntaxErrors'
    updated_at = <Date 2021-10-04.19:18:42.967>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2021-10-04.19:18:42.967>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-09-25.09:33:00.119>
    closer = 'lukasz.langa'
    components = ['Parser']
    creation = <Date 2021-04-22.18:08:10.767>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43914
    keywords = ['patch']
    message_count = 10.0
    messages = ['391620', '391697', '391729', '391808', '402611', '402615', '402616', '402711', '402713', '403163']
    nosy_count = 7.0
    nosy_names = ['terry.reedy', 'aroberge', 'eric.araujo', 'lukasz.langa', 'lys.nikolaou', 'pablogsal', 'miss-islington']
    pr_nums = ['25525', '25582', '28558', '28562', '28576', '28582']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43914'
    versions = ['Python 3.10', 'Python 3.11']

    @pablogsal
    Copy link
    Member Author

    To improve the user experience understanding what part of the error messages associated to SyntaxErrors are wrong, we can highlight the whole error range and not only place the caret at the first character. In this way:

    >>> foo(x, z for z in range(10), t, w)
      File "<stdin>", line 1
        foo(x, z for z in range(10), t, w)
               ^
    SyntaxError: Generator expression must be parenthesized

    becomes

    >>> foo(x, z for z in range(10), t, w)
      File "<stdin>", line 1
        foo(x, z for z in range(10), t, w)
               ^^^^^^^^^^^^^^^^^^^^
    SyntaxError: Generator expression must be parenthesized

    @pablogsal pablogsal added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Apr 22, 2021
    @pablogsal
    Copy link
    Member Author

    New changeset a77aac4 by Pablo Galindo in branch 'master':
    bpo-43914: Highlight invalid ranges in SyntaxErrors (bpo-25525)
    a77aac4

    @merwok
    Copy link
    Member

    merwok commented Apr 23, 2021

    What a great, useful change!

    @terryjreedy
    Copy link
    Member

    Great!!!  I also tried
    >>> try: compile("a xyzjdkjfk", '', 'single')
    except SyntaxError as e:
    	print(e, e.msg, e.lineno, e.offset, e.end_lineno, e.end_offset)

    invalid syntax. Perhaps you forgot a comma? (, line 1) invalid syntax. Perhaps you forgot a comma? 1 1 1 12

    The language change that enables the display change is the addition of end_lineno and end_offset attributes. I will look into using these in IDLE. I will submit a PR to augment the What's New entry, so others can also improve their error marking.

    @ambv
    Copy link
    Contributor

    ambv commented Sep 25, 2021

    New changeset 71f8ff4 by Terry Jan Reedy in branch 'main':
    bpo-43914: Whats New 310: add new SyntaxError attributes (GH-28558)
    71f8ff4

    @ambv
    Copy link
    Contributor

    ambv commented Sep 25, 2021

    New changeset c523022 by Łukasz Langa in branch '3.10':
    [3.10] bpo-43914: What's New 3.10: add new SyntaxError attributes (GH-28558) (GH-28562)
    c523022

    @ambv
    Copy link
    Contributor

    ambv commented Sep 25, 2021

    This is complete now. Thanks! ✨ 🍰 ✨

    @ambv ambv added the 3.11 only security fixes label Sep 25, 2021
    @ambv ambv closed this as completed Sep 25, 2021
    @ambv ambv added the 3.11 only security fixes label Sep 25, 2021
    @ambv ambv closed this as completed Sep 25, 2021
    @pablogsal
    Copy link
    Member Author

    New changeset e5f13ce by Pablo Galindo Salgado in branch 'main':
    bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576)
    e5f13ce

    @miss-islington
    Copy link
    Contributor

    New changeset 9e209d4 by Miss Islington (bot) in branch '3.10':
    bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576)
    9e209d4

    @pablogsal
    Copy link
    Member Author

    New changeset 0eb57c3 by Pablo Galindo (Łukasz Langa) in branch '3.10':
    [3.10] bpo-43914: What's New 3.10: add new SyntaxError attributes (GH-28558) (GH-28562)
    0eb57c3

    New changeset 3397e31 by Pablo Galindo (Miss Islington (bot)) in branch '3.10':
    bpo-43914: Correctly highlight SyntaxError exceptions for invalid generator expression in function calls (GH-28576)
    3397e31

    @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 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants