Fix #151 (again!): yield inside with wasn't propagated to Result

This commit is contained in:
Ryan Gonzalez 2017-03-08 10:37:45 -06:00
parent 484daafa53
commit 7c82c01a6a
3 changed files with 27 additions and 16 deletions

2
NEWS
View File

@ -15,6 +15,8 @@ Changes from 0.12.1
* Shadowed comparison operators now use `and` instead of `&`
for chained comparisons
* partition no longer prematurely exhausts input iterators
* A `yield` inside of a `with` statement will properly suppress implicit
returns.
Changes from 0.12.0

View File

@ -1485,6 +1485,7 @@ class HyASTCompiler(object):
optional_vars=thing)]
ret = ctx + the_with
ret.contains_yield = ret.contains_yield or body.contains_yield
# And make our expression context our temp variable
expr_name = ast.Name(id=ast_str(var), arg=ast_str(var),
ctx=ast.Load(),

View File

@ -724,6 +724,14 @@
(with [(open "README.md" "r")] (do)))
(defn test-context-yield []
"NATIVE: test yields inside of with statements don't try to return before Python 3.3"
(defn f []
(with [(open "README.md")] (yield 123)))
(assert (= (next (f)) 123)))
(defn test-with-return []
"NATIVE: test that with returns stuff"
(defn read-file [filename]