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

Incorrect syntax error message for incorrect argument unpacking #110696

Closed
thatbirdguythatuknownot opened this issue Oct 11, 2023 · 3 comments
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@thatbirdguythatuknownot
Copy link
Contributor

thatbirdguythatuknownot commented Oct 11, 2023

Bug report

Bug description:

I don't think SyntaxError: iterable argument unpacking follows keyword argument unpacking should be present in a case like this (minimal reproducible example):

>>> func(t, *:)
  File "<stdin>", line 1
    func(t, *:)
         ^
SyntaxError: iterable argument unpacking follows keyword argument unpacking

So it seems like if * is followed by code that triggers a generic SyntaxError: invalid syntax error, the former error triggers and overshadows the generic error. This has somewhat made checking the error in the expression following that * a bit harder.
I have another question. func(a=5, *b) is apparently allowed but from the error func(**{'a': 7}, *b) isn't? I don't know what the PEP is for this so I'll try to search it up later.

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

@thatbirdguythatuknownot thatbirdguythatuknownot added the type-bug An unexpected behavior, bug, or error label Oct 11, 2023
@Eclips4
Copy link
Member

Eclips4 commented Oct 11, 2023

cc @pablogsal

pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 11, 2023
@pablogsal pablogsal changed the title Wrong error message? Incorrect syntax error message for incorrect argument unpacking Oct 11, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 11, 2023
@terryjreedy terryjreedy added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 11, 2023
@thatbirdguythatuknownot
Copy link
Contributor Author

thatbirdguythatuknownot commented Oct 12, 2023

As for my question, it seems that func(a=5, *b) shouldn't be valid? All the other alternative ways to write it are invalid syntax.

# not allowed
func(a=5, 1, 2)
func(**{'a': 5}, 1, 2)
func(**{'a': 5}, *(1, 2))
# allowed
func(a=7, *(1, 2))

I might have to follow this up with a different issue.

pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 12, 2023
…ect argument unpacking (pythonGH-110706)

(cherry picked from commit 3d18034)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 12, 2023
…ect argument unpacking (pythonGH-110706)

(cherry picked from commit 3d18034)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@pablogsal
Copy link
Member

pablogsal commented Oct 12, 2023

As for my question, it seems that func(a=5, *b) shouldn't be valid? All the other alternative ways to write it are invalid syntax.

It was valid before (3.9 and older) so we cannot just make invalid now for backwards compatibility reasons.

pablogsal added a commit that referenced this issue Oct 12, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 13, 2023
… incorrect argument unpacking (pythonGH-110706) (cherry picked from commit 3d18034)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants