Remove tuple unpacking in lambda lists
This commit is contained in:
parent
bb10921ace
commit
a2aeca2338
2
NEWS.rst
2
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
|
||||
------------------------------
|
||||
|
@ -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.
|
||||
|
@ -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))")
|
||||
|
@ -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])
|
||||
|
Loading…
Reference in New Issue
Block a user