This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error range of "duplicate argument" SyntaxErrors is too big
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Carl.Friedrich.Bolz, aroberge, miss-islington, pablogsal
Priority: normal Keywords: patch

Created on 2021-12-10 21:24 by Carl.Friedrich.Bolz, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30059 merged pablogsal, 2021-12-11 17:41
PR 30064 merged miss-islington, 2021-12-11 21:28
Messages (10)
msg408248 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-12-10 21:24
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.
msg408250 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-10 22:27
Thanks for the catch Carl!

> I can try to fix this.

Awesome, I will wait for the PR!
msg408298 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-12-11 12:46
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'
msg408322 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-11 17:41
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.
msg408323 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-12-11 17:47
Oh no, I was about to open mine ;-)

bpo-46042-syntax-error-range-duplicate-argument?expand=1">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)
msg408324 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-12-11 17:48
ah, confused, seems you fixed them both too. will take a closer look!
msg408343 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-11 21:28
New changeset 59435eea08d30796174552c0ca03c59b41adf8a5 by Pablo Galindo Salgado in branch 'main':
bpo-46042: Improve SyntaxError locations in the symbol table (GH-30059)
https://github.com/python/cpython/commit/59435eea08d30796174552c0ca03c59b41adf8a5
msg408344 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-11 21:32
> 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!!
msg408356 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-12 01:24
New changeset 438817fdd5b731d486285d205bed2e78b655c0d6 by Miss Islington (bot) in branch '3.10':
bpo-46042: Improve SyntaxError locations in the symbol table (GH-30059) (GH-30064)
https://github.com/python/cpython/commit/438817fdd5b731d486285d205bed2e78b655c0d6
msg408360 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-12-12 05:24
Oh, don't worry, it's all good! It got fixed and I learned something.
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90200
2021-12-12 05:24:58Carl.Friedrich.Bolzsetmessages: + msg408360
2021-12-12 01:24:16pablogsalsetmessages: + msg408356
2021-12-11 21:32:05pablogsalsetmessages: + msg408344
2021-12-11 21:29:46pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-12-11 21:28:46miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28284
2021-12-11 21:28:34pablogsalsetmessages: + msg408343
2021-12-11 17:48:13Carl.Friedrich.Bolzsetmessages: + msg408324
2021-12-11 17:47:21Carl.Friedrich.Bolzsetmessages: + msg408323
2021-12-11 17:41:53pablogsalsetmessages: + msg408322
2021-12-11 17:41:06pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28279
2021-12-11 12:46:23Carl.Friedrich.Bolzsetmessages: + msg408298
2021-12-10 22:27:14pablogsalsetmessages: + msg408250
2021-12-10 21:44:50arobergesetnosy: + aroberge
2021-12-10 21:24:21Carl.Friedrich.Bolzcreate