Remove tuple unpacking in lambda lists

This commit is contained in:
Kodi Arfer 2018-04-20 09:27:44 -07:00
parent bb10921ace
commit a2aeca2338
4 changed files with 5 additions and 35 deletions

View File

@ -9,6 +9,8 @@ Removals
These were redundant with Python's built-in data structures and Hy's most These were redundant with Python's built-in data structures and Hy's most
common model types (`HyExpression`, `HyList`, etc.). common model types (`HyExpression`, `HyList`, etc.).
* `&key` is no longer special in lambda lists. Use `&optional` instead. * `&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 Other Breaking Changes
------------------------------ ------------------------------

View File

@ -553,6 +553,8 @@ class HyASTCompiler(object):
continue continue
if lambda_keyword is None: if lambda_keyword is None:
if not isinstance(expr, HySymbol):
raise HyTypeError(expr, "Parameters must be symbols")
args.append(expr) args.append(expr)
elif lambda_keyword == "&rest": elif lambda_keyword == "&rest":
if varargs: if varargs:
@ -1893,19 +1895,6 @@ class HyASTCompiler(object):
(ret, args, defaults, stararg, (ret, args, defaults, stararg,
kwonlyargs, kwonlydefaults, kwargs) = self._parse_lambda_list(arglist) 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 # Before Python 3.7, docstrings must come at the start, so ensure that
# happens even if we generate anonymous variables. # happens even if we generate anonymous variables.

View File

@ -414,12 +414,6 @@ def test_ast_tuple():
assert type(code) == 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(): def test_lambda_list_keywords_rest():
""" Ensure we can compile functions with lambda list keywords.""" """ Ensure we can compile functions with lambda list keywords."""
can_compile("(fn [x &rest xs] (print xs))") can_compile("(fn [x &rest xs] (print xs))")

View File

@ -1761,11 +1761,6 @@ macros()
(= (identify-keywords 1 "bloo" :foo) (= (identify-keywords 1 "bloo" :foo)
["other" "other" "keyword"]))) ["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 #@(pytest.mark.xfail
(defn test-assert-multistatements [] (defn test-assert-multistatements []
; https://github.com/hylang/hy/issues/1390 ; https://github.com/hylang/hy/issues/1390
@ -1789,21 +1784,11 @@ macros()
(defn f [] "docstring" 5) (defn f [] "docstring" 5)
(assert (= (. f __doc__) "docstring")) (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 ; a single string is the return value, not a docstring
; (https://github.com/hylang/hy/issues/1402) ; (https://github.com/hylang/hy/issues/1402)
(defn f3 [] "not a docstring") (defn f3 [] "not a docstring")
(assert (none? (. f3 __doc__))) (assert (none? (. f3 __doc__)))
(assert (= (f3) "not a docstring")) (assert (= (f3) "not a docstring")))
(defn f4 [[a b]] "not a docstring")
(assert (none? (. f4 __doc__)))
(assert (= (f4 [1 2]) "not a docstring")))
(defn test-module-docstring [] (defn test-module-docstring []
(import [tests.resources.module-docstring-example :as m]) (import [tests.resources.module-docstring-example :as m])