Fix #151 (again!): yield inside with wasn't propagated to Result
This commit is contained in:
parent
484daafa53
commit
7c82c01a6a
2
NEWS
2
NEWS
|
@ -15,6 +15,8 @@ Changes from 0.12.1
|
||||||
* Shadowed comparison operators now use `and` instead of `&`
|
* Shadowed comparison operators now use `and` instead of `&`
|
||||||
for chained comparisons
|
for chained comparisons
|
||||||
* partition no longer prematurely exhausts input iterators
|
* partition no longer prematurely exhausts input iterators
|
||||||
|
* A `yield` inside of a `with` statement will properly suppress implicit
|
||||||
|
returns.
|
||||||
|
|
||||||
Changes from 0.12.0
|
Changes from 0.12.0
|
||||||
|
|
||||||
|
|
|
@ -1485,6 +1485,7 @@ class HyASTCompiler(object):
|
||||||
optional_vars=thing)]
|
optional_vars=thing)]
|
||||||
|
|
||||||
ret = ctx + the_with
|
ret = ctx + the_with
|
||||||
|
ret.contains_yield = ret.contains_yield or body.contains_yield
|
||||||
# And make our expression context our temp variable
|
# And make our expression context our temp variable
|
||||||
expr_name = ast.Name(id=ast_str(var), arg=ast_str(var),
|
expr_name = ast.Name(id=ast_str(var), arg=ast_str(var),
|
||||||
ctx=ast.Load(),
|
ctx=ast.Load(),
|
||||||
|
|
|
@ -724,6 +724,14 @@
|
||||||
(with [(open "README.md" "r")] (do)))
|
(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 []
|
(defn test-with-return []
|
||||||
"NATIVE: test that with returns stuff"
|
"NATIVE: test that with returns stuff"
|
||||||
(defn read-file [filename]
|
(defn read-file [filename]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user