diff options
author | 2020-05-21 18:14:55 -0700 | |
---|---|---|
committer | 2020-05-21 18:14:55 -0700 | |
commit | 55c89235247d9dbe8a4463c9c64edc7e48826a44 (patch) | |
tree | fca57eb9f5e6214769255f0dd314dc68a7dc408f /Grammar | |
parent | [doc] Remove references to obsolete BuildApplet on macOS. (GH-20023) (GH-20304) (diff) | |
download | cpython-55c89235247d9dbe8a4463c9c64edc7e48826a44.tar.gz cpython-55c89235247d9dbe8a4463c9c64edc7e48826a44.tar.bz2 cpython-55c89235247d9dbe8a4463c9c64edc7e48826a44.zip |
bpo-40334: Produce better error messages for non-parenthesized genexps (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 ae145833025b0156ee2a28219e3370f3b27b2a36)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index a771abf46fd..19d9bb36fed 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -627,6 +627,9 @@ incorrect_arguments: | args ',' '*' { RAISE_SYNTAX_ERROR("iterable argument unpacking follows keyword argument unpacking") } | a=expression for_if_clauses ',' [args | expression for_if_clauses] { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "Generator expression must be parenthesized") } + | a=args for_if_clauses { _PyPegen_nonparen_genexp_in_call(p, a) } + | args ',' a=expression for_if_clauses { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "Generator expression must be parenthesized") } | a=args ',' args { _PyPegen_arguments_parsing_error(p, a) } invalid_kwarg: | a=expression '=' { |