summaryrefslogtreecommitdiffstats
path: root/Grammar/python.gram
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-10 13:24:41 (GMT)
committerGitHub <noreply@github.com>2020-06-10 13:24:41 (GMT)
commitd55ed7b10794b6ee6a04a564e6d714368d520c15 (patch)
tree05d4765bbf53bc711a496866dfd058efc91e1aa9 /Grammar/python.gram
parent73b728a779aa7d6d8f088c4b21447bba4bf3a351 (diff)
downloadcpython-d55ed7b10794b6ee6a04a564e6d714368d520c15.zip
cpython-d55ed7b10794b6ee6a04a564e6d714368d520c15.tar.gz
cpython-d55ed7b10794b6ee6a04a564e6d714368d520c15.tar.bz2
Raise specialised syntax error for invalid lambda parameters (GH-20776)
(cherry picked from commit c6483c989694cfa328dabd45eb191440da54bc68) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Grammar/python.gram')
-rw-r--r--Grammar/python.gram9
1 files changed, 8 insertions, 1 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index dd425ef..2c350ef 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -329,7 +329,11 @@ expression[expr_ty] (memo):
| lambdef
lambdef[expr_ty]:
- | 'lambda' a=[lambda_parameters] ':' b=expression { _Py_Lambda((a) ? a : CHECK(_PyPegen_empty_arguments(p)), b, EXTRA) }
+ | 'lambda' a=[lambda_params] ':' b=expression { _Py_Lambda((a) ? a : CHECK(_PyPegen_empty_arguments(p)), b, EXTRA) }
+
+lambda_params[arguments_ty]:
+ | invalid_lambda_parameters
+ | lambda_parameters
# lambda_parameters etc. duplicates parameters but without annotations
# or type comments, and if there's no comma after a parameter, we expect
@@ -669,6 +673,9 @@ invalid_dict_comprehension:
invalid_parameters:
| param_no_default* (slash_with_default | param_with_default+) param_no_default {
RAISE_SYNTAX_ERROR("non-default argument follows default argument") }
+invalid_lambda_parameters:
+ | lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default {
+ RAISE_SYNTAX_ERROR("non-default argument follows default argument") }
invalid_star_etc:
| '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
| '*' ',' TYPE_COMMENT { RAISE_SYNTAX_ERROR("bare * has associated type comment") }