Allow &rest after &optional, like Python

This commit is contained in:
Kodi Arfer 2016-10-11 13:31:22 -07:00
parent 11481aba78
commit 108537a4e0
2 changed files with 4 additions and 8 deletions

View File

@ -503,19 +503,13 @@ class HyASTCompiler(object):
for expr in exprs:
if expr in ll_keywords:
if expr == "&rest" and lambda_keyword is None:
lambda_keyword = expr
elif expr == "&optional":
if expr == "&optional":
if len(defaults) > 0:
raise HyTypeError(expr,
"There can only be &optional "
"arguments or one &key argument")
lambda_keyword = expr
elif expr == "&key":
lambda_keyword = expr
elif expr == "&kwonly":
lambda_keyword = expr
elif expr == "&kwargs":
elif expr in ("&rest", "&key", "&kwonly", "&kwargs"):
lambda_keyword = expr
else:
raise HyTypeError(expr,

View File

@ -397,6 +397,7 @@ def test_lambda_list_keywords_rest():
""" Ensure we can compile functions with lambda list keywords."""
can_compile("(fn (x &rest xs) (print xs))")
cant_compile("(fn (x &rest xs &rest ys) (print xs))")
can_compile("(fn (&optional a &rest xs) (print xs))")
def test_lambda_list_keywords_key():
@ -410,6 +411,7 @@ def test_lambda_list_keywords_kwargs():
""" Ensure we can compile functions with &kwargs."""
can_compile("(fn (x &kwargs kw) (list x kw))")
cant_compile("(fn (x &kwargs xs &kwargs ys) (list x xs ys))")
can_compile("(fn (&optional x &kwargs kw) (list x kw))")
def test_lambda_list_keywords_kwonly():