Merge pull request #1312 from Kodiologist/remove-py2-yield-from
Remove the Python 2 yield-from macro
This commit is contained in:
commit
c3c7af2db3
1
NEWS
1
NEWS
@ -1,6 +1,7 @@
|
|||||||
Changes from 0.13.0
|
Changes from 0.13.0
|
||||||
|
|
||||||
[ Language Changes ]
|
[ Language Changes ]
|
||||||
|
* `yield-from` is no longer supported under Python 2
|
||||||
* Single-character "sharp macros" changed to "tag macros", which can have
|
* Single-character "sharp macros" changed to "tag macros", which can have
|
||||||
longer names
|
longer names
|
||||||
* Periods are no longer allowed in keywords
|
* Periods are no longer allowed in keywords
|
||||||
|
@ -1128,13 +1128,9 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@builds("yield_from")
|
@builds_if("yield_from", PY3)
|
||||||
@checkargs(max=1)
|
@checkargs(max=1)
|
||||||
def compile_yield_from_expression(self, expr):
|
def compile_yield_from_expression(self, expr):
|
||||||
if not PY3:
|
|
||||||
raise HyCompileError(
|
|
||||||
"yield-from only supported in python 3.3+!")
|
|
||||||
|
|
||||||
expr.pop(0)
|
expr.pop(0)
|
||||||
ret = Result(contains_yield=True)
|
ret = Result(contains_yield=True)
|
||||||
|
|
||||||
|
@ -201,24 +201,6 @@
|
|||||||
`(do (setv ~@(interleave ~gs ~os))
|
`(do (setv ~@(interleave ~gs ~os))
|
||||||
~@~body)))
|
~@~body)))
|
||||||
|
|
||||||
(if-python2
|
|
||||||
(defmacro/g! yield-from [expr]
|
|
||||||
`(do (import types)
|
|
||||||
(setv ~g!iter (iter ~expr))
|
|
||||||
(setv ~g!return None)
|
|
||||||
(setv ~g!message None)
|
|
||||||
(while True
|
|
||||||
(try (if (isinstance ~g!iter types.GeneratorType)
|
|
||||||
(setv ~g!message (yield (.send ~g!iter ~g!message)))
|
|
||||||
(setv ~g!message (yield (next ~g!iter))))
|
|
||||||
(except [~g!e StopIteration]
|
|
||||||
(do (setv ~g!return (if (hasattr ~g!e "value")
|
|
||||||
(. ~g!e value)
|
|
||||||
None))
|
|
||||||
(break)))))
|
|
||||||
~g!return))
|
|
||||||
None)
|
|
||||||
|
|
||||||
|
|
||||||
(defmacro defmain [args &rest body]
|
(defmacro defmain [args &rest body]
|
||||||
"Write a function named \"main\" and do the if __main__ dance"
|
"Write a function named \"main\" and do the if __main__ dance"
|
||||||
|
@ -306,31 +306,6 @@
|
|||||||
(assert (= (lif-not 0 "false" "true") "true")))
|
(assert (= (lif-not 0 "false" "true") "true")))
|
||||||
|
|
||||||
|
|
||||||
(defn test-yield-from []
|
|
||||||
"NATIVE: testing yield from"
|
|
||||||
(defn yield-from-test []
|
|
||||||
(for* [i (range 3)]
|
|
||||||
(yield i))
|
|
||||||
(yield-from [1 2 3]))
|
|
||||||
(assert (= (list (yield-from-test)) [0 1 2 1 2 3])))
|
|
||||||
|
|
||||||
(defn test-yield-from-exception-handling []
|
|
||||||
"NATIVE: Ensure exception handling in yield from works right"
|
|
||||||
(defn yield-from-subgenerator-test []
|
|
||||||
(yield 1)
|
|
||||||
(yield 2)
|
|
||||||
(yield 3)
|
|
||||||
(assert 0))
|
|
||||||
(defn yield-from-test []
|
|
||||||
(for* [i (range 3)]
|
|
||||||
(yield i))
|
|
||||||
(try
|
|
||||||
(yield-from (yield-from-subgenerator-test))
|
|
||||||
(except [e AssertionError]
|
|
||||||
(yield 4))))
|
|
||||||
(assert (= (list (yield-from-test)) [0 1 2 1 2 3 4])))
|
|
||||||
|
|
||||||
|
|
||||||
(defn test-defmain []
|
(defn test-defmain []
|
||||||
"NATIVE: make sure defmain is clean"
|
"NATIVE: make sure defmain is clean"
|
||||||
(global --name--)
|
(global --name--)
|
||||||
|
@ -35,3 +35,29 @@
|
|||||||
(assert (= (apply function-of-various-args
|
(assert (= (apply function-of-various-args
|
||||||
[1 2 3 4] {"foo" 5 "bar" 6 "quux" 7})
|
[1 2 3 4] {"foo" 5 "bar" 6 "quux" 7})
|
||||||
(, 1 2 (, 3 4) 5 {"bar" 6 "quux" 7}))))
|
(, 1 2 (, 3 4) 5 {"bar" 6 "quux" 7}))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-yield-from []
|
||||||
|
"NATIVE: testing yield from"
|
||||||
|
(defn yield-from-test []
|
||||||
|
(for* [i (range 3)]
|
||||||
|
(yield i))
|
||||||
|
(yield-from [1 2 3]))
|
||||||
|
(assert (= (list (yield-from-test)) [0 1 2 1 2 3])))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-yield-from-exception-handling []
|
||||||
|
"NATIVE: Ensure exception handling in yield from works right"
|
||||||
|
(defn yield-from-subgenerator-test []
|
||||||
|
(yield 1)
|
||||||
|
(yield 2)
|
||||||
|
(yield 3)
|
||||||
|
(assert 0))
|
||||||
|
(defn yield-from-test []
|
||||||
|
(for* [i (range 3)]
|
||||||
|
(yield i))
|
||||||
|
(try
|
||||||
|
(yield-from (yield-from-subgenerator-test))
|
||||||
|
(except [e AssertionError]
|
||||||
|
(yield 4))))
|
||||||
|
(assert (= (list (yield-from-test)) [0 1 2 1 2 3 4])))
|
||||||
|
Loading…
Reference in New Issue
Block a user