diff --git a/NEWS.rst b/NEWS.rst index 4270da5..b5903a4 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -9,6 +9,8 @@ Removals These were redundant with Python's built-in data structures and Hy's most common model types (`HyExpression`, `HyList`, etc.). * `&key` is no longer special in lambda lists. Use `&optional` instead. +* Tuple unpacking is no longer built into special forms for function + definition (`fn` etc.) Other Breaking Changes ------------------------------ diff --git a/hy/compiler.py b/hy/compiler.py index cb2a3d1..a4ba4e1 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -553,6 +553,8 @@ class HyASTCompiler(object): continue if lambda_keyword is None: + if not isinstance(expr, HySymbol): + raise HyTypeError(expr, "Parameters must be symbols") args.append(expr) elif lambda_keyword == "&rest": if varargs: @@ -1893,19 +1895,6 @@ class HyASTCompiler(object): (ret, args, defaults, stararg, kwonlyargs, kwonlydefaults, kwargs) = self._parse_lambda_list(arglist) - for i, arg in enumerate(args): - if isinstance(arg, HyList): - # Destructuring argument - if not arg: - raise HyTypeError(arglist, - "Cannot destruct empty list") - args[i] = var = HySymbol(self.get_anon_var()) - expression = HyExpression([ - HyExpression([ - HySymbol("setv"), arg, var - ])] - ) + expression - expression = expression.replace(arg[0]) # Before Python 3.7, docstrings must come at the start, so ensure that # happens even if we generate anonymous variables. diff --git a/hy/contrib/walk.hy b/hy/contrib/walk.hy index 28093ed..507cf42 100644 --- a/hy/contrib/walk.hy +++ b/hy/contrib/walk.hy @@ -166,7 +166,7 @@ Arguments without a header are under None. (for [[header section] (-> self (.tail) first lambda-list .items)] (if header (.append argslist header)) (cond [(in header [None '&rest '&kwargs]) - (.update protected (-> section flatten set)) + (.update protected section) (.extend argslist section)] [(in header '[&optional &kwonly]) (for [pair section] diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 9b9b16e..b1e7ef8 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -414,12 +414,6 @@ def test_ast_tuple(): assert type(code) == ast.Tuple -def test_argument_destructuring(): - """ Ensure argument destructuring compilers. """ - can_compile("(fn [[a b]] (print a b))") - cant_compile("(fn [[]] 0)") - - def test_lambda_list_keywords_rest(): """ Ensure we can compile functions with lambda list keywords.""" can_compile("(fn [x &rest xs] (print xs))") diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index ad1f00f..fbda979 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -1761,11 +1761,6 @@ macros() (= (identify-keywords 1 "bloo" :foo) ["other" "other" "keyword"]))) -(defn test-argument-destr [] - "Make sure argument destructuring works" - (defn f [[a b] [c]] (, a b c)) - (assert (= (f [1 2] [3]) (, 1 2 3)))) - #@(pytest.mark.xfail (defn test-assert-multistatements [] ; https://github.com/hylang/hy/issues/1390 @@ -1789,21 +1784,11 @@ macros() (defn f [] "docstring" 5) (assert (= (. f __doc__) "docstring")) - ; destructuring and the implicit variables it creates - ; shouldn't interfere with docstrings - ; (https://github.com/hylang/hy/issues/1409) - (defn f2 [[a b]] "docstring" 5) - (assert (= (. f2 __doc__) "docstring")) - ; a single string is the return value, not a docstring ; (https://github.com/hylang/hy/issues/1402) (defn f3 [] "not a docstring") (assert (none? (. f3 __doc__))) - (assert (= (f3) "not a docstring")) - - (defn f4 [[a b]] "not a docstring") - (assert (none? (. f4 __doc__))) - (assert (= (f4 [1 2]) "not a docstring"))) + (assert (= (f3) "not a docstring"))) (defn test-module-docstring [] (import [tests.resources.module-docstring-example :as m])