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

Error range of "duplicate argument" SyntaxErrors is too big #90200

Closed
cfbolz mannequin opened this issue Dec 10, 2021 · 10 comments
Closed

Error range of "duplicate argument" SyntaxErrors is too big #90200

cfbolz mannequin opened this issue Dec 10, 2021 · 10 comments

Comments

@cfbolz
Copy link
Mannequin

cfbolz mannequin commented Dec 10, 2021

BPO 46042
Nosy @cfbolz, @aroberge, @pablogsal, @miss-islington
PRs
  • bpo-46042: Improve SyntaxError locations in the symbol table #30059
  • [3.10] bpo-46042: Improve SyntaxError locations in the symbol table (GH-30059) #30064
  • 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-12-11.21:29:46.835>
    created_at = <Date 2021-12-10.21:24:21.180>
    labels = []
    title = 'Error range of "duplicate argument" SyntaxErrors is too big'
    updated_at = <Date 2021-12-12.05:24:58.584>
    user = 'https://github.com/cfbolz'

    bugs.python.org fields:

    activity = <Date 2021-12-12.05:24:58.584>
    actor = 'Carl.Friedrich.Bolz'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-12-11.21:29:46.835>
    closer = 'pablogsal'
    components = []
    creation = <Date 2021-12-10.21:24:21.180>
    creator = 'Carl.Friedrich.Bolz'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46042
    keywords = ['patch']
    message_count = 10.0
    messages = ['408248', '408250', '408298', '408322', '408323', '408324', '408343', '408344', '408356', '408360']
    nosy_count = 4.0
    nosy_names = ['Carl.Friedrich.Bolz', 'aroberge', 'pablogsal', 'miss-islington']
    pr_nums = ['30059', '30064']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46042'
    versions = []

    @cfbolz
    Copy link
    Mannequin Author

    cfbolz mannequin commented Dec 10, 2021

    The error range for the "duplicate argument in function definition" SyntaxError is too large:

    $ cat x.py 
    def f(a, b, c, d, e, f, g, a): pass
    $ python x.py
      File "/home/cfbolz/projects/cpython/x.py", line 1
        def f(a, b, c, d, e, f, g, a): pass
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    SyntaxError: duplicate argument 'a' in function definition

    I would expect only the second 'a' to be underlined.

    I can try to fix this.

    @pablogsal
    Copy link
    Member

    Thanks for the catch Carl!

    I can try to fix this.

    Awesome, I will wait for the PR!

    @cfbolz
    Copy link
    Mannequin Author

    cfbolz mannequin commented Dec 11, 2021

    let's see whether I promised too much, I don't know CPython's symtable.c too well yet ;-). Will shout for help when I get stuck.

    Anyway, here is a related bug, coming from the same symtable function symtable_add_def_helper, also with an imprecise error location:

    $ cat x.py 
    {i for i in range(5)
            if (j := 0)
                for j in range(5)}
    
    $ ./python x.py 
      File "/home/cfbolz/projects/cpython/x.py", line 1
        {i for i in range(5)
        ^^^^^^^^^^^^^^^^^^^^
    SyntaxError: comprehension inner loop cannot rebind assignment expression target 'j'

    @pablogsal
    Copy link
    Member

    Don't worry, turns out it was a bit messier than I thought, so I prepared the PR. If you have some time, it would be great if you can take a quick look.

    @cfbolz
    Copy link
    Mannequin Author

    cfbolz mannequin commented Dec 11, 2021

    Oh no, I was about to open mine ;-)

    https://github.com/python/cpython/compare/main...cfbolz:bpo-46042-syntax-error-range-duplicate-argument?expand=1

    Basically equivalent, but I fixed the second bug too (would be very easy to add to yours)

    @cfbolz
    Copy link
    Mannequin Author

    cfbolz mannequin commented Dec 11, 2021

    ah, confused, seems you fixed them both too. will take a closer look!

    @pablogsal
    Copy link
    Member

    New changeset 59435ee by Pablo Galindo Salgado in branch 'main':
    bpo-46042: Improve SyntaxError locations in the symbol table (GH-30059)
    59435ee

    @pablogsal
    Copy link
    Member

    Oh no, I was about to open mine ;-)

    Sorry, Carl, I apologize. I hope it was not too disruptive to do the work. I was taking a look and I felt bad that the issue was probably messier than I thought and I didn't want you to have to iterate many times :(

    Thanks a lot for helping review the PR and for pointing out the extra cases!!

    @pablogsal
    Copy link
    Member

    New changeset 438817f by Miss Islington (bot) in branch '3.10':
    bpo-46042: Improve SyntaxError locations in the symbol table (GH-30059) (GH-30064)
    438817f

    @cfbolz
    Copy link
    Mannequin Author

    cfbolz mannequin commented Dec 12, 2021

    Oh, don't worry, it's all good! It got fixed and I learned something.

    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant