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

bpo-40334: Produce better error messages for non-parenthesized genexps #20153

Merged
merged 5 commits into from May 22, 2020

Conversation

lysnikolaou
Copy link
Contributor

@lysnikolaou lysnikolaou commented May 17, 2020

The error message, generated for non-parenthesized generator expression
in function calls, was still the generic invalid syntax, when the
generator expression wasn't appearing as the first argument in the call.
Now, even on inputs like f(a, b, c for c in d, e), the correct error
message gets produced.

PS Last one with this bpo number. Promise!

https://bugs.python.org/issue40334

The error message, generated for non-parenthesized generator expression
in function calls, was still the generic `invalid syntax`, when the
generator expression wasn't appearing as the first argument in the call.
Now, even on input like `f(a, b, c for c in d, e)`, the correct error
message gets produced.
@pablogsal
Copy link
Member

Humm, there are still some mistmatches. For instance:

>>> f(x=3,x for x in L,)
  File "<stdin>", line 1
    f(x=3,x for x in L,)
            ^
SyntaxError: positional argument follows keyword argument

with the old parser:

>>> f(x=3,x for x in L,)
  File "<stdin>", line 1
SyntaxError: Generator expression must be parenthesized

@lysnikolaou
Copy link
Contributor Author

Humm, there are still some mistmatches. For instance:

>>> f(x=3,x for x in L,)
  File "<stdin>", line 1
    f(x=3,x for x in L,)
            ^
SyntaxError: positional argument follows keyword argument

with the old parser:

>>> f(x=3,x for x in L,)
  File "<stdin>", line 1
SyntaxError: Generator expression must be parenthesized

Fixed in ed64876.

@lysnikolaou lysnikolaou added the needs backport to 3.9 only security fixes label May 19, 2020
@lysnikolaou
Copy link
Contributor Author

@pablogsal Would you be able to give this another review?

@pablogsal
Copy link
Member

@pablogsal Would you be able to give this another review?

Absolutely, will try to review this tonight :)

@lysnikolaou
Copy link
Contributor Author

@pablogsal Would you be able to give this another review?

Absolutely, will try to review this tonight :)

No rush, whenever you find the time.

@pablogsal
Copy link
Member

LGTM

I have been playing with some edge cases and it behaves as expected 🎉

@pablogsal pablogsal merged commit ae14583 into python:master May 22, 2020
@miss-islington
Copy link
Contributor

Thanks @lysnikolaou for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 22, 2020
pythonGH-20153)

The error message, generated for a non-parenthesized generator expression
in function calls, was still the generic `invalid syntax`, when the generator expression wasn't appearing as the first argument in the call. With this patch, even on input like `f(a, b, c for c in d, e)`, the correct error message gets produced.
(cherry picked from commit ae14583)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label May 22, 2020
@bedevere-bot
Copy link

GH-20307 is a backport of this pull request to the 3.9 branch.

@lysnikolaou lysnikolaou deleted the nonparen-genxp branch May 22, 2020 01:00
@lysnikolaou
Copy link
Contributor Author

Thanks thanks!

miss-islington added a commit that referenced this pull request May 22, 2020
GH-20153)

The error message, generated for a non-parenthesized generator expression
in function calls, was still the generic `invalid syntax`, when the generator expression wasn't appearing as the first argument in the call. With this patch, even on input like `f(a, b, c for c in d, e)`, the correct error message gets produced.
(cherry picked from commit ae14583)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
arturoescaip pushed a commit to arturoescaip/cpython that referenced this pull request May 24, 2020
pythonGH-20153)

The error message, generated for a non-parenthesized generator expression
in function calls, was still the generic `invalid syntax`, when the generator expression wasn't appearing as the first argument in the call. With this patch, even on input like `f(a, b, c for c in d, e)`, the correct error message gets produced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants