summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-04 10:58:31 (GMT)
committerGitHub <noreply@github.com>2020-05-04 10:58:31 (GMT)
commite10e7c771bf06112c4a311e0ef6b8af6423b0cca (patch)
tree79a34dfffd7b555dcab60db13ad4ab678d4b9068 /Grammar
parentc3f001461d5794c81cf5f70e08ae5435fe935ceb (diff)
downloadcpython-e10e7c771bf06112c4a311e0ef6b8af6423b0cca.zip
cpython-e10e7c771bf06112c4a311e0ef6b8af6423b0cca.tar.gz
cpython-e10e7c771bf06112c4a311e0ef6b8af6423b0cca.tar.bz2
bpo-40334: Spacialized error message for invalid args after bare '*' (GH-19865)
When parsing things like `def f(*): pass` the old parser used to output `SyntaxError: named arguments must follow bare *`, which the new parser wasn't able to do.
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram6
1 files changed, 6 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 8e49490..0ce6ab4 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -249,6 +249,7 @@ star_etc[StarEtc*]:
| '*' ',' b=param_maybe_default+ c=[kwds] {
_PyPegen_star_etc(p, NULL, b, c) }
| a=kwds { _PyPegen_star_etc(p, NULL, NULL, a) }
+ | invalid_star_etc
kwds[arg_ty]: '**' a=param_no_default { a }
@@ -356,6 +357,7 @@ lambda_star_etc[StarEtc*]:
| '*' ',' b=lambda_param_maybe_default+ c=[lambda_kwds] {
_PyPegen_star_etc(p, NULL, b, c) }
| a=lambda_kwds { _PyPegen_star_etc(p, NULL, NULL, a) }
+ | invalid_lambda_star_etc
lambda_kwds[arg_ty]: '**' a=lambda_param_no_default { a }
@@ -636,6 +638,10 @@ invalid_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_star_etc:
+ | '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
+invalid_lambda_star_etc:
+ | '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
invalid_double_type_comments:
| TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT {
RAISE_SYNTAX_ERROR("Cannot have two type comments on def") }