Make setv
always return None
This commit is contained in:
parent
61f4277104
commit
ae1dd78c53
2
NEWS
2
NEWS
@ -7,6 +7,7 @@ Changes from 0.12.1
|
||||
* Added bytestring literals, which create `bytes` objects under Python 3
|
||||
and `str` objects under Python 2
|
||||
* Commas and underscores are allowed in numeric literals
|
||||
* `setv` always returns None
|
||||
* with-decorator: Allow a `setv` form as the form to be decorated
|
||||
* xor: If exactly one argument is true, return it
|
||||
* hy.core.reserved is now hy.extra.reserved
|
||||
@ -19,6 +20,7 @@ Changes from 0.12.1
|
||||
parses to a false value (e.g., the empty string)
|
||||
* A `yield` inside of a `with` statement will properly suppress implicit
|
||||
returns.
|
||||
* `setv` no longer unnecessarily tries to get attributes
|
||||
|
||||
Changes from 0.12.0
|
||||
|
||||
|
@ -2156,16 +2156,9 @@ class HyASTCompiler(object):
|
||||
root))
|
||||
else:
|
||||
result = Result()
|
||||
exprs = []
|
||||
for tgt, target in zip(expression[::2], expression[1::2]):
|
||||
item = self._compile_assign(tgt, target,
|
||||
tgt.start_line, tgt.start_column)
|
||||
result += item
|
||||
exprs.append(item.force_expr)
|
||||
|
||||
result += ast.Tuple(elts=exprs, lineno=expression.start_line,
|
||||
col_offset=expression.start_column,
|
||||
ctx=ast.Load())
|
||||
result += self._compile_assign(tgt, target, tgt.start_line,
|
||||
tgt.start_column)
|
||||
return result
|
||||
|
||||
def _compile_assign(self, name, result,
|
||||
@ -2196,7 +2189,6 @@ class HyASTCompiler(object):
|
||||
targets=[st_name],
|
||||
value=result.force_expr)
|
||||
|
||||
result += ld_name
|
||||
return result
|
||||
|
||||
@builds("for*")
|
||||
|
@ -81,10 +81,12 @@
|
||||
(setv x 1)
|
||||
(setv y 1)
|
||||
(assert-equal x y)
|
||||
(setv x (setv y 12))
|
||||
(setv y 12)
|
||||
(setv x y)
|
||||
(assert-equal x 12)
|
||||
(assert-equal y 12)
|
||||
(setv x (setv y (fn [x] 9)))
|
||||
(setv y (fn [x] 9))
|
||||
(setv x y)
|
||||
(assert-equal (x y) 9)
|
||||
(assert-equal (y x) 9)
|
||||
(try (do (setv a.b 1) (assert False))
|
||||
|
@ -51,11 +51,6 @@
|
||||
(assert (= #{} (set))))
|
||||
|
||||
|
||||
(defn test-setv-empty []
|
||||
"NATIVE: test setv works with no arguments"
|
||||
(assert (is (setv) None)))
|
||||
|
||||
|
||||
(defn test-setv-get []
|
||||
"NATIVE: test setv works on a get expression"
|
||||
(setv foo [0 1 2])
|
||||
@ -81,15 +76,49 @@
|
||||
|
||||
(defn test-setv-pairs []
|
||||
"NATIVE: test that setv works on pairs of arguments"
|
||||
(assert (= (setv a 1 b 2) (, 1 2)))
|
||||
(setv a 1 b 2)
|
||||
(assert (= a 1))
|
||||
(assert (= b 2))
|
||||
(setv y 0 x 1 y x)
|
||||
(assert y)
|
||||
(assert (= y 1))
|
||||
(try (eval '(setv a 1 b))
|
||||
(except [e [TypeError]] (assert (in "`setv' needs an even number of arguments" (str e))))))
|
||||
|
||||
|
||||
(defn test-setv-returns-none []
|
||||
"NATIVE: test that setv always returns None"
|
||||
|
||||
(assert (none? (setv)))
|
||||
(assert (none? (setv x 1)))
|
||||
(assert (= x 1))
|
||||
(assert (none? (setv x 2)))
|
||||
(assert (= x 2))
|
||||
(assert (none? (setv y 2 z 3)))
|
||||
(assert (= y 2))
|
||||
(assert (= z 3))
|
||||
(assert (none? (setv [y z] [7 8])))
|
||||
(assert (= y 7))
|
||||
(assert (= z 8))
|
||||
(assert (none? (setv (, y z) [9 10])))
|
||||
(assert (= y 9))
|
||||
(assert (= z 10))
|
||||
|
||||
(setv p 11)
|
||||
(setv p (setv q 12))
|
||||
(assert (= q 12))
|
||||
(assert (none? p))
|
||||
|
||||
; https://github.com/hylang/hy/issues/1052
|
||||
(assert (none? (setv (get {} "x") 42)))
|
||||
(setv l [])
|
||||
(defclass Foo [object]
|
||||
[__setattr__ (fn [self attr val]
|
||||
(.append l [attr val]))])
|
||||
(setv x (Foo))
|
||||
(assert (none? (setv x.eggs "ham")))
|
||||
(assert (not (hasattr x "eggs")))
|
||||
(assert (= l [["eggs" "ham"]])))
|
||||
|
||||
(defn test-store-errors []
|
||||
"NATIVE: test that setv raises the correct errors when given wrong argument types"
|
||||
(try
|
||||
|
@ -49,8 +49,8 @@
|
||||
(defn test-builtin-decorator-reader []
|
||||
(defn increment-arguments [func]
|
||||
"Increments each argument passed to the decorated function."
|
||||
#@((wraps func)
|
||||
(defn wrapper [&rest args &kwargs kwargs]
|
||||
((wraps func)
|
||||
(fn [&rest args &kwargs kwargs]
|
||||
(apply func
|
||||
(map inc args)
|
||||
(dict-comp k (inc v) [[k v] (.items kwargs)])))))
|
||||
|
@ -39,8 +39,8 @@
|
||||
(defn test-decorator-clobbing []
|
||||
"NATIVE: Tests whether nested decorators work"
|
||||
(do
|
||||
(defn dec1 [f] (defn k [] (+ (f) 1)))
|
||||
(defn dec2 [f] (defn k [] (+ (f) 2)))
|
||||
(defn dec1 [f] (fn [] (+ (f) 1)))
|
||||
(defn dec2 [f] (fn [] (+ (f) 2)))
|
||||
(with-decorator dec1
|
||||
(with-decorator dec2
|
||||
(defn f [] 1)))
|
||||
|
Loading…
Reference in New Issue
Block a user